sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit cd73d1b33012414cb76fc64f81964b5fb66b673f
parent 6e0f5c14093c7edadb556f1862dab432ad4826c2
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Sat, 12 May 2012 17:54:36 +0100

grep: check regcomp succeeds
Diffstat:
Mgrep.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/grep.c b/grep.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { char c; - int flags = REG_NOSUB; + int n, flags = REG_NOSUB; regex_t preg; FILE *fp; @@ -46,8 +46,13 @@ main(int argc, char *argv[]) } if(optind == argc) enprintf(Error, "usage: %s [-Ecilnqv] pattern [files...]\n", argv[0]); - regcomp(&preg, argv[optind++], flags); + if((n = regcomp(&preg, argv[optind++], flags)) != 0) { + char buf[BUFSIZ]; + + regerror(n, &preg, buf, sizeof buf); + enprintf(Error, "%s\n", buf); + } many = (argc > optind+1); if(optind == argc) grep(stdin, "<stdin>", &preg);