summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Longeau <chl@cvs.openbsd.org>2007-09-25 11:35:01 +0000
committerCharles Longeau <chl@cvs.openbsd.org>2007-09-25 11:35:01 +0000
commitabdbca130827f2345d4090bc5c66b81fce25d0e0 (patch)
tree7363e8027a90b9485818fd9ea5e6ac1e83157569
parent733bab3ca6eda50ba4bc43b20ed4cb96c25aff1b (diff)
handle empty strings returned by fgets
use strcspn to properly overwrite '\n' in fgets returned buffer ok ray@
-rw-r--r--usr.bin/tn3270/tools/mkhits/dohits.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/usr.bin/tn3270/tools/mkhits/dohits.c b/usr.bin/tn3270/tools/mkhits/dohits.c
index 5e6ba71805e..11059beabbf 100644
--- a/usr.bin/tn3270/tools/mkhits/dohits.c
+++ b/usr.bin/tn3270/tools/mkhits/dohits.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dohits.c,v 1.8 2003/06/03 02:56:20 millert Exp $ */
+/* $OpenBSD: dohits.c,v 1.9 2007/09/25 11:35:00 chl Exp $ */
/*-
* Copyright (c) 1988 The Regents of the University of California.
@@ -31,7 +31,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)dohits.c 4.2 (Berkeley) 4/26/91";*/
-static char rcsid[] = "$OpenBSD: dohits.c,v 1.8 2003/06/03 02:56:20 millert Exp $";
+static char rcsid[] = "$OpenBSD: dohits.c,v 1.9 2007/09/25 11:35:00 chl Exp $";
#endif /* not lint */
/*
@@ -133,7 +133,7 @@ char *file, /* Name of file to scan for whitespace prefix */
}
break;
}
- } while (line[strlen(line)-1] != '\n');
+ } while (strchr(line, '\n') == NULL);
}
}
@@ -173,7 +173,7 @@ char *file, /* Name of file to scan for #define prefix */
}
break;
}
- } while (line[strlen(line)-1] != '\n');
+ } while (strchr(line, '\n') == NULL);
}
}
@@ -257,8 +257,7 @@ char *aidfile, *fcnfile;
scanwhite(fcnfile, "FCN_");
while (fgets(line, sizeof(line), stdin) != NULL) {
- if (line[strlen(line)-1] == '\n')
- line[strlen(line)-1] = '\0';
+ line[strcspn(line, "\n")] = '\0';
if (!isdigit(line[0])) {
continue;
}