瀏覽代碼

Do not access invalid lastdir

master
Arun Prakash Jana 5 年之前
父節點
當前提交
ef88a31a7c
沒有發現已知的金鑰在資料庫的簽署中 GPG 金鑰 ID: A75979F35C080412
共有 1 個檔案被更改,包括 25 行新增1 行删除
  1. +25
    -1
      src/nnn.c

+ 25
- 1
src/nnn.c 查看文件

@@ -4132,6 +4132,7 @@ static void browse(char *ipath, const char *session)
char rundir[PATH_MAX] __attribute__ ((aligned)); char rundir[PATH_MAX] __attribute__ ((aligned));
char runfile[NAME_MAX + 1] __attribute__ ((aligned)); char runfile[NAME_MAX + 1] __attribute__ ((aligned));
uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT)); uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
uint utmp;
int r = -1, fd, presel, selstartid = 0, selendid = 0; int r = -1, fd, presel, selstartid = 0, selendid = 0;
ino_t inode = 0; ino_t inode = 0;
enum action sel; enum action sel;
@@ -4172,7 +4173,7 @@ static void browse(char *ipath, const char *session)
errexit(); errexit();


begin: begin:
if (cfg.selmode && nselected)
if (cfg.selmode && nselected && lastdir[0])
updateselbuf(lastdir, newpath); updateselbuf(lastdir, newpath);


#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
@@ -4804,6 +4805,16 @@ nochange:
if (rangesel) if (rangesel)
rangesel = FALSE; rangesel = FALSE;


/* Write the path to selection file to avoid flush */
if (!(dents[cur].flags & FILE_SELECTED)) {
utmp = selbufpos;
appendfpath(newpath, mkpath(path, dents[cur].name, newpath));
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
selbufpos = utmp;
}

/* Toggle selection status */
dents[cur].flags ^= FILE_SELECTED; dents[cur].flags ^= FILE_SELECTED;
dents[cur].flags ? ++nselected : --nselected; dents[cur].flags ? ++nselected : --nselected;


@@ -4862,11 +4873,24 @@ nochange:
selendid = ndents - 1; selendid = ndents - 1;
} }


/* Remember current selection buffer position */
utmp = selbufpos;

for (r = selstartid; r <= selendid; ++r) for (r = selstartid; r <= selendid; ++r)
if (!(dents[r].flags & FILE_SELECTED)) { if (!(dents[r].flags & FILE_SELECTED)) {
/* Write the path to selection file to avoid flush */
appendfpath(newpath, mkpath(path, dents[r].name, newpath));

dents[r].flags |= FILE_SELECTED; dents[r].flags |= FILE_SELECTED;
++nselected; ++nselected;
} }

if (selbufpos != utmp) {
writesel(pselbuf, selbufpos - 1); /* Truncate NULL from end */
spawn(copier, NULL, NULL, NULL, F_NOTRACE);
/* Restore current selection buffer position */
selbufpos = utmp;
}
continue; continue;
case SEL_SELLIST: case SEL_SELLIST:
if (listselbuf(path, newpath) || listselfile()) { if (listselbuf(path, newpath) || listselfile()) {


Loading…
取消
儲存