Declare error buffer at start of block

This commit is contained in:
sin 2014-05-12 00:39:56 +01:00
parent fb1bfe24bb
commit 11eef783fe

3
grep.c
View File

@ -112,6 +112,7 @@ addpattern(const char *pattern)
bool bool
grep(FILE *fp, const char *str, int flags) grep(FILE *fp, const char *str, int flags)
{ {
char err[BUFSIZ];
char *buf = NULL; char *buf = NULL;
long n, c = 0; long n, c = 0;
int r; int r;
@ -123,8 +124,6 @@ grep(FILE *fp, const char *str, int flags)
for(n = 1; afgets(&buf, &size, fp); n++) { for(n = 1; afgets(&buf, &size, fp); n++) {
for(pnode = phead; pnode; pnode = pnode->next) { for(pnode = phead; pnode; pnode = pnode->next) {
if((r = regcomp(&preg, pnode->pattern, flags)) != 0) { if((r = regcomp(&preg, pnode->pattern, flags)) != 0) {
char err[BUFSIZ];
regerror(r, &preg, err, sizeof err); regerror(r, &preg, err, sizeof err);
enprintf(Error, "invalid pattern: %s\n", err); enprintf(Error, "invalid pattern: %s\n", err);
} }