diff options
author | Charles Longeau <chl@cvs.openbsd.org> | 2007-11-28 18:20:40 +0000 |
---|---|---|
committer | Charles Longeau <chl@cvs.openbsd.org> | 2007-11-28 18:20:40 +0000 |
commit | e7d4f489f7080cae14807710d9ae988d0799381c (patch) | |
tree | 0a90c836bee3031b592602fb3ea2b0eae2e2d8c3 | |
parent | a669e3158c630c02666a52c479490553287d5db1 (diff) |
use sizeof (buf) instead of hardcoded value
use strcspn to properly overwrite '\n' in fgets returned buffer
ok ray@
-rw-r--r-- | gnu/usr.sbin/mkhybrid/src/libfile/apprentice.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/gnu/usr.sbin/mkhybrid/src/libfile/apprentice.c b/gnu/usr.sbin/mkhybrid/src/libfile/apprentice.c index fecc3086291..fd98f50e65d 100644 --- a/gnu/usr.sbin/mkhybrid/src/libfile/apprentice.c +++ b/gnu/usr.sbin/mkhybrid/src/libfile/apprentice.c @@ -42,7 +42,7 @@ #ifndef lint static char *moduleid = - "@(#)$Id: apprentice.c,v 1.1 2000/10/10 20:40:36 beck Exp $"; + "@(#)$Id: apprentice.c,v 1.2 2007/11/28 18:20:39 chl Exp $"; #endif /* lint */ #define EATAB {while (isascii((unsigned char) *l) && \ @@ -97,12 +97,13 @@ int check; /* non-zero? checking-only run. */ if (check) /* print silly verbose header for USG compat. */ (void) printf("%s\n", hdr); - for (lineno = 1;fgets(line, BUFSIZ, f) != NULL; lineno++) { + for (lineno = 1;fgets(line, sizeof(line), f) != NULL; lineno++) { if (line[0]=='#') /* comment, do not parse */ continue; - if (strlen(line) <= (unsigned)1) /* null line, garbage, etc */ + /* delete newline */ + line[strcspn(line, "\n")] = '\0'; + if (line[0] == '\0') continue; - line[strlen(line)-1] = '\0'; /* delete newline */ if (parse(line, &nmagic, check) != 0) errs = 1; } |