Explicitly check for '\0' at the start and exit early
This commit is contained in:
parent
c2db1b9ec6
commit
ed9985205b
@ -95,12 +95,11 @@ checkheader(FILE *fp, const char *s, const char *header, mode_t *mode, char **fn
|
|||||||
char *p, *q;
|
char *p, *q;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
if (fgets(bufs, sizeof(bufs), fp) == NULL) {
|
if (fgets(bufs, sizeof(bufs), fp) == NULL)
|
||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
eprintf("%s: read error:", s);
|
eprintf("%s: read error:", s);
|
||||||
else
|
if (bufs[0] == '\0' || feof(fp))
|
||||||
eprintf("empty or null header string\n");
|
eprintf("empty or nil header string\n");
|
||||||
}
|
|
||||||
if ((p = strchr(bufs, '\n')) == NULL)
|
if ((p = strchr(bufs, '\n')) == NULL)
|
||||||
eprintf("header string too long or non-newline terminated file\n");
|
eprintf("header string too long or non-newline terminated file\n");
|
||||||
p = bufs;
|
p = bufs;
|
||||||
|
Loading…
Reference in New Issue
Block a user