[hackers] [sbase] grep: check regcomp succeeds || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Sat, 12 May 2012 18:54:40 +0200 (CEST)

changeset: 114:c52aecfc53fe
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sat May 12 17:54:36 2012 +0100
files: grep.c
description:
grep: check regcomp succeeds


diff -r e4d795417dad -r c52aecfc53fe grep.c
--- a/grep.c Thu May 10 19:20:16 2012 +0100
+++ b/grep.c Sat May 12 17:54:36 2012 +0100
_AT_@ -20,7 +20,7 @@
 main(int argc, char *argv[])
 {
         char c;
- int flags = REG_NOSUB;
+ int n, flags = REG_NOSUB;
         regex_t preg;
         FILE *fp;
 
_AT_@ -46,8 +46,13 @@
                 }
         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);
Received on Sat May 12 2012 - 18:54:40 CEST

This archive was generated by hypermail 2.3.0 : Sat May 12 2012 - 19:00:10 CEST