Fix segfault in tail(1)

We should not be looking at optarg, that's uninitialized.  We
are not using getopt.
This commit is contained in:
sin 2013-08-31 21:53:11 +01:00
parent fd262561a9
commit 7d4d519a51

7
tail.c
View File

@ -21,11 +21,13 @@ main(int argc, char *argv[])
long n = 10;
FILE *fp;
void (*tail)(FILE *, const char *, long) = taketail;
char *lines;
ARGBEGIN {
case 'n':
n = abs(estrtol(EARGF(usage()), 0));
if(optarg[0] == '+')
lines = EARGF(usage());
n = abs(estrtol(lines, 0));
if(lines[0] == '+')
tail = dropinit;
break;
default:
@ -79,4 +81,3 @@ taketail(FILE *fp, const char *str, long n)
free(ring);
free(size);
}