ngctl: Fix getline loop
I misremembered when I wrote this code: getline() returns -1 on EOF, not
zero, so the loop condition and the error check are both incorrect
(though in practice getline() will never return 0).
MFC after: 3 days
Fixes: 3cbdcabf71 ("ngctl: Modernize code somewhat")
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D55487
This commit is contained in:
@@ -243,7 +243,7 @@ ReadFile(FILE *fp)
|
|||||||
unsigned int lineno = 0;
|
unsigned int lineno = 0;
|
||||||
int rtn = CMDRTN_OK;
|
int rtn = CMDRTN_OK;
|
||||||
|
|
||||||
while ((len = getline(&line, &sz, fp)) > 0) {
|
while ((len = getline(&line, &sz, fp)) >= 0) {
|
||||||
lineno++;
|
lineno++;
|
||||||
if (*line == '#')
|
if (*line == '#')
|
||||||
continue;
|
continue;
|
||||||
@@ -252,7 +252,7 @@ ReadFile(FILE *fp)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (len < 0)
|
if (ferror(fp))
|
||||||
rtn = CMDRTN_ERROR;
|
rtn = CMDRTN_ERROR;
|
||||||
free(line);
|
free(line);
|
||||||
return (rtn);
|
return (rtn);
|
||||||
|
|||||||
Reference in New Issue
Block a user