Pārlūkot izejas kodu

Use early error checks

Early check for empty file name in populate().
Check access before calling populate().
Drop populate() return type.
master
Arun Prakash Jana pirms 5 gadiem
vecāks
revīzija
b6842d69c5
Šim parakstam datu bāzē netika atrasta zināma atslēga GPG atslēgas ID: A75979F35C080412
1 mainītis faili ar 18 papildinājumiem un 16 dzēšanām
  1. +18
    -16
      src/nnn.c

+ 18
- 16
src/nnn.c Parādīt failu

@@ -2480,14 +2480,14 @@ static int dentfill(char *path, struct entry **dents)
return n; return n;
} }


/* Return the position of the matching entry or 0 otherwise */
/*
* Return the position of the matching entry or 0 otherwise
* Note there's no NULL check for fname
*/
static int dentfind(const char *fname, int n) static int dentfind(const char *fname, int n)
{ {
static int i; static int i;


if (!fname)
return 0;

DPRINTF_S(fname); DPRINTF_S(fname);


for (i = 0; i < n; ++i) for (i = 0; i < n; ++i)
@@ -2497,14 +2497,8 @@ static int dentfind(const char *fname, int n)
return 0; return 0;
} }


static bool populate(char *path, char *lastname)
static void populate(char *path, char *lastname)
{ {
/* Can fail when permissions change while browsing.
* It's assumed that path IS a directory when we are here.
*/
if (access(path, R_OK) == -1)
return FALSE;

if (cfg.blkorder) { if (cfg.blkorder) {
printmsg("calculating..."); printmsg("calculating...");
refresh(); refresh();
@@ -2518,7 +2512,7 @@ static bool populate(char *path, char *lastname)


ndents = dentfill(path, &dents); ndents = dentfill(path, &dents);
if (!ndents) if (!ndents)
return TRUE;
return;


qsort(dents, ndents, sizeof(*dents), entrycmp); qsort(dents, ndents, sizeof(*dents), entrycmp);


@@ -2528,8 +2522,11 @@ static bool populate(char *path, char *lastname)
#endif #endif


/* Find cur from history */ /* Find cur from history */
cur = dentfind(lastname, ndents);
return TRUE;
/* No NULL check for lastname, always points to an array */
if (!*lastname)
cur = 0;
else
dentfind(lastname, ndents);
} }


static void redraw(char *path) static void redraw(char *path)
@@ -2749,11 +2746,16 @@ begin:
} }
#endif #endif


if (!populate(path, lastname)) {
/* Can fail when permissions change while browsing.
* It's assumed that path IS a directory when we are here.
*/
if (access(path, R_OK) == -1) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }


populate(path, lastname);

#ifdef LINUX_INOTIFY #ifdef LINUX_INOTIFY
if (inotify_wd == -1) if (inotify_wd == -1)
inotify_wd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK); inotify_wd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK);
@@ -3659,7 +3661,7 @@ nochange:
if (ndents) if (ndents)
copycurname(); copycurname();


/* Re-populate as directory content may have changed */
/* Repopulate as directory content may have changed */
goto begin; goto begin;
case SEL_QUITCD: // fallthrough case SEL_QUITCD: // fallthrough
case SEL_QUIT: case SEL_QUIT:


Notiek ielāde…
Atcelt
Saglabāt