浏览代码

Remove sizeof() is absolute cases

master
Arun Prakash Jana 8 年前
父节点
当前提交
64d06ccaee
找不到此签名对应的密钥 GPG 密钥 ID: A75979F35C080412
共有 1 个文件被更改,包括 45 次插入47 次删除
  1. +45
    -47
      nnn.c

+ 45
- 47
nnn.c 查看文件

@@ -441,8 +441,8 @@ setfilter(regex_t *regex, char *filter)
r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE); r = regcomp(regex, filter, REG_NOSUB | REG_EXTENDED | REG_ICASE);
if (r != 0) { if (r != 0) {
len = COLS; len = COLS;
if (len > sizeof(errbuf))
len = sizeof(errbuf);
if (len > LINE_MAX)
len = LINE_MAX;
regerror(r, regex, errbuf, len); regerror(r, regex, errbuf, len);
printmsg(errbuf); printmsg(errbuf);
} }
@@ -596,9 +596,8 @@ fill(struct entry **dents,
{ {
static struct entry _dent; static struct entry _dent;
static int count, n; static int count, n;
n = 0;


for (count = 0; count < ndents; count++) {
for (count = 0, n = 0; count < ndents; count++) {
if (filter(re, (*dents)[count].name) == 0) if (filter(re, (*dents)[count].name) == 0)
continue; continue;


@@ -678,7 +677,6 @@ readln(char *path)
goto end; goto end;
} }



if (matches(pln) == -1) if (matches(pln) == -1)
goto end; goto end;


@@ -712,7 +710,7 @@ readln(char *path)
redraw(path); redraw(path);
printprompt(ln); printprompt(ln);
} }
} else if (r == KEY_CODE_YES) {
} else {
switch(*ch) { switch(*ch) {
case KEY_DC: case KEY_DC:
case KEY_BACKSPACE: case KEY_BACKSPACE:
@@ -1227,9 +1225,9 @@ dentfill(char *path, struct entry **dents,
printerr(1, "realloc"); printerr(1, "realloc");
} }


xstrlcpy((*dents)[n].name, dp->d_name, sizeof((*dents)[n].name));
xstrlcpy((*dents)[n].name, dp->d_name, NAME_MAX);
/* Get mode flags */ /* Get mode flags */
mkpath(path, dp->d_name, newpath, sizeof(newpath));
mkpath(path, dp->d_name, newpath, PATH_MAX);
r = lstat(newpath, &sb); r = lstat(newpath, &sb);
if (r == -1) { if (r == -1) {
if (*dents) if (*dents)
@@ -1428,8 +1426,8 @@ browse(char *ipath, char *ifilter)
int r, fd, filtered = FALSE; int r, fd, filtered = FALSE;
enum action sel = SEL_RUNARG + 1; enum action sel = SEL_RUNARG + 1;


xstrlcpy(path, ipath, sizeof(path));
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(path, ipath, PATH_MAX);
xstrlcpy(fltr, ifilter, LINE_MAX);
oldpath[0] = '\0'; oldpath[0] = '\0';
newpath[0] = '\0'; newpath[0] = '\0';
lastdir[0] = '\0'; /* Can't move back from initial directory */ lastdir[0] = '\0'; /* Can't move back from initial directory */
@@ -1478,20 +1476,20 @@ nochange:
} }


/* Save history */ /* Save history */
xstrlcpy(oldpath, path, sizeof(oldpath));
xstrlcpy(oldpath, path, PATH_MAX);


/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, dir, sizeof(path));
xstrlcpy(lastdir, path, PATH_MAX);
xstrlcpy(path, dir, PATH_MAX);
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
goto begin; goto begin;
case SEL_GOIN: case SEL_GOIN:
/* Cannot descend in empty directories */ /* Cannot descend in empty directories */
if (ndents == 0) if (ndents == 0)
goto begin; goto begin;


mkpath(path, dents[cur].name, newpath, sizeof(newpath));
mkpath(path, dents[cur].name, newpath, PATH_MAX);
DPRINTF_S(newpath); DPRINTF_S(newpath);


/* Get path info */ /* Get path info */
@@ -1517,12 +1515,12 @@ nochange:
} }


/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(lastdir, path, PATH_MAX);


xstrlcpy(path, newpath, sizeof(path));
xstrlcpy(path, newpath, PATH_MAX);
oldpath[0] = '\0'; oldpath[0] = '\0';
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
goto begin; goto begin;
case S_IFREG: case S_IFREG:
{ {
@@ -1577,11 +1575,11 @@ nochange:
} }
case SEL_FLTR: case SEL_FLTR:
filtered = readln(path); filtered = readln(path);
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(fltr); DPRINTF_S(fltr);
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto nochange; goto nochange;
case SEL_NEXT: case SEL_NEXT:
if (cur < ndents - 1) if (cur < ndents - 1)
@@ -1668,7 +1666,7 @@ nochange:
} }


/* Switch to last visited dir */ /* Switch to last visited dir */
xstrlcpy(newpath, lastdir, sizeof(newpath));
xstrlcpy(newpath, lastdir, PATH_MAX);
truecd = 1; truecd = 1;
} else if ((r = all_dots(tmp))) { } else if ((r = all_dots(tmp))) {
if (r == 1) { if (r == 1) {
@@ -1708,13 +1706,13 @@ nochange:
/* Save the path in case of cd .. /* Save the path in case of cd ..
We mark the current dir in parent dir */ We mark the current dir in parent dir */
if (r == 1) { if (r == 1) {
xstrlcpy(oldpath, path, sizeof(oldpath));
xstrlcpy(oldpath, path, PATH_MAX);
truecd = 2; truecd = 2;
} }


xstrlcpy(newpath, dir, sizeof(newpath));
xstrlcpy(newpath, dir, PATH_MAX);
} else } else
mkpath(path, tmp, newpath, sizeof(newpath));
mkpath(path, tmp, newpath, PATH_MAX);


if (canopendir(newpath) == 0) { if (canopendir(newpath) == 0) {
printwarn(); printwarn();
@@ -1736,13 +1734,13 @@ nochange:
oldpath[0] = '\0'; oldpath[0] = '\0';


/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(lastdir, path, PATH_MAX);


/* Save the newly opted dir in path */ /* Save the newly opted dir in path */
xstrlcpy(path, newpath, sizeof(path));
xstrlcpy(path, newpath, PATH_MAX);


/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(path); DPRINTF_S(path);
free(input); free(input);
goto begin; goto begin;
@@ -1763,12 +1761,12 @@ nochange:
break; break;


/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(lastdir, path, PATH_MAX);


xstrlcpy(path, tmp, sizeof(path));
xstrlcpy(path, tmp, PATH_MAX);
oldpath[0] = '\0'; oldpath[0] = '\0';
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(path); DPRINTF_S(path);
goto begin; goto begin;
case SEL_CDBEGIN: case SEL_CDBEGIN:
@@ -1781,12 +1779,12 @@ nochange:
break; break;


/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(lastdir, path, PATH_MAX);


xstrlcpy(path, ipath, sizeof(path));
xstrlcpy(path, ipath, PATH_MAX);
oldpath[0] = '\0'; oldpath[0] = '\0';
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(path); DPRINTF_S(path);
goto begin; goto begin;
case SEL_CDLAST: case SEL_CDLAST:
@@ -1798,18 +1796,18 @@ nochange:
goto nochange; goto nochange;
} }


xstrlcpy(newpath, lastdir, sizeof(newpath));
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, newpath, sizeof(path));
xstrlcpy(newpath, lastdir, PATH_MAX);
xstrlcpy(lastdir, path, PATH_MAX);
xstrlcpy(path, newpath, PATH_MAX);
oldpath[0] = '\0'; oldpath[0] = '\0';
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
DPRINTF_S(path); DPRINTF_S(path);
goto begin; goto begin;
case SEL_TOGGLEDOT: case SEL_TOGGLEDOT:
showhidden ^= 1; showhidden ^= 1;
initfilter(showhidden, &ifilter); initfilter(showhidden, &ifilter);
xstrlcpy(fltr, ifilter, sizeof(fltr));
xstrlcpy(fltr, ifilter, LINE_MAX);
goto begin; goto begin;
case SEL_DETAIL: case SEL_DETAIL:
showdetail = !showdetail; showdetail = !showdetail;
@@ -1817,14 +1815,14 @@ nochange:
: (printptr = &printent); : (printptr = &printent);
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto begin; goto begin;
case SEL_STATS: case SEL_STATS:
{ {
struct stat sb; struct stat sb;


if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);


r = lstat(oldpath, &sb); r = lstat(oldpath, &sb);
if (r == -1) { if (r == -1) {
@@ -1845,7 +1843,7 @@ nochange:
} }
case SEL_MEDIA: case SEL_MEDIA:
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);


exitcurses(); exitcurses();
r = show_mediainfo(oldpath, FALSE); r = show_mediainfo(oldpath, FALSE);
@@ -1857,7 +1855,7 @@ nochange:
break; break;
case SEL_FMEDIA: case SEL_FMEDIA:
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);


exitcurses(); exitcurses();
r = show_mediainfo(oldpath, TRUE); r = show_mediainfo(oldpath, TRUE);
@@ -1881,7 +1879,7 @@ nochange:
bsizeorder = 0; bsizeorder = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto begin; goto begin;
case SEL_BSIZE: case SEL_BSIZE:
bsizeorder = !bsizeorder; bsizeorder = !bsizeorder;
@@ -1893,7 +1891,7 @@ nochange:
sizeorder = 0; sizeorder = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto begin; goto begin;
case SEL_MTIME: case SEL_MTIME:
mtimeorder = !mtimeorder; mtimeorder = !mtimeorder;
@@ -1901,12 +1899,12 @@ nochange:
bsizeorder = 0; bsizeorder = 0;
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto begin; goto begin;
case SEL_REDRAW: case SEL_REDRAW:
/* Save current */ /* Save current */
if (ndents > 0) if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
mkpath(path, dents[cur].name, oldpath, PATH_MAX);
goto begin; goto begin;
case SEL_COPY: case SEL_COPY:
if (copier && ndents) { if (copier && ndents) {
@@ -2005,7 +2003,7 @@ main(int argc, char *argv[])


if (argc == optind) { if (argc == optind) {
/* Start in the current directory */ /* Start in the current directory */
ipath = getcwd(cwd, sizeof(cwd));
ipath = getcwd(cwd, PATH_MAX);
if (ipath == NULL) if (ipath == NULL)
ipath = "/"; ipath = "/";
} else { } else {


正在加载...
取消
保存