diff options
author | 2015-08-27 05:11:39 +0000 | |
---|---|---|
committer | 2015-08-27 05:11:39 +0000 | |
commit | 220c68d6df6331f5a853441166456555132503aa (patch) | |
tree | d4990d0111ccc8350af24162f27c3fc48cf79ac3 /usr.bin/grep/grep.c | |
parent | ELF uberalles: remove #ifdef _NLIST_DO_ELF tests (diff) | |
download | wireguard-openbsd-220c68d6df6331f5a853441166456555132503aa.tar.xz wireguard-openbsd-220c68d6df6331f5a853441166456555132503aa.zip |
use strtonum to parse the number of lines of context.
this provides better error messages.
ok deraadt@ guenther@
Diffstat (limited to 'usr.bin/grep/grep.c')
-rw-r--r-- | usr.bin/grep/grep.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 041d81ec9f8..ddaabd23566 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.51 2015/04/30 13:49:04 millert Exp $ */ +/* $OpenBSD: grep.c,v 1.52 2015/08/27 05:11:39 dlg Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -235,7 +235,8 @@ main(int argc, char *argv[]) int c, lastc, prevoptind, newarg, i, needpattern, exprs, expr_sz; struct patfile *patfile, *pf_next; long l; - char *ep, **expr; + char **expr; + const char *errstr; SLIST_INIT(&patfilelh); switch (__progname[0]) { @@ -279,10 +280,9 @@ main(int argc, char *argv[]) break; case 'A': case 'B': - l = strtol(optarg, &ep, 10); - if (ep == optarg || *ep != '\0' || - l <= 0 || l >= INT_MAX) - errx(2, "context out of range"); + l = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr != NULL) + errx(2, "context %s", errstr); if (c == 'A') Aflag = (int)l; else @@ -292,10 +292,9 @@ main(int argc, char *argv[]) if (optarg == NULL) Aflag = Bflag = 2; else { - l = strtol(optarg, &ep, 10); - if (ep == optarg || *ep != '\0' || - l <= 0 || l >= INT_MAX) - errx(2, "context out of range"); + l = strtonum(optarg, 1, INT_MAX, &errstr); + if (errstr != NULL) + errx(2, "context %s", errstr); Aflag = Bflag = (int)l; } break; |