Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/tip Check getchar() result for EOF.
details: https://anonhg.NetBSD.org/src/rev/90e72a995565
branches: trunk
changeset: 839486:90e72a995565
user: uwe <uwe%NetBSD.org@localhost>
date: Fri Feb 22 22:25:22 2019 +0000
description:
Check getchar() result for EOF.
Call cleanup(SIGHUP) if we get local EOF, as if we've got SIGHUP.
While here, use EOF constant instead of literal -1 in an existing
check.
PR bin/53996
diffstat:
usr.bin/tip/tip.c | 28 ++++++++++++++++++++++------
1 files changed, 22 insertions(+), 6 deletions(-)
diffs (77 lines):
diff -r 7e10d7fe7787 -r 90e72a995565 usr.bin/tip/tip.c
--- a/usr.bin/tip/tip.c Fri Feb 22 22:20:18 2019 +0000
+++ b/usr.bin/tip/tip.c Fri Feb 22 22:25:22 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tip.c,v 1.60 2019/02/06 14:08:50 rin Exp $ */
+/* $NetBSD: tip.c,v 1.61 2019/02/22 22:25:22 uwe Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: tip.c,v 1.60 2019/02/06 14:08:50 rin Exp $");
+__RCSID("$NetBSD: tip.c,v 1.61 2019/02/22 22:25:22 uwe Exp $");
#endif /* not lint */
/*
@@ -304,7 +304,7 @@
unraw();
(void)printf("%s", s);
if (setjmp(promptbuf) == 0)
- while ((c = getchar()) != -1 && (*p = c) != '\n' &&
+ while ((c = getchar()) != EOF && (*p = c) != '\n' &&
b + l > p)
p++;
*p = '\0';
@@ -330,6 +330,22 @@
}
/*
+ * getchar() wrapper that checks for EOF on the local end.
+ */
+static char
+xgetchar(void)
+{
+ int c = getchar();
+ if (__predict_false(c == EOF)) {
+ cleanup(SIGHUP);
+ /* NOTREACHED */
+ }
+
+ return (char)c & STRIP_PAR;
+}
+
+
+/*
* ****TIPIN TIPIN****
*/
static void
@@ -350,7 +366,7 @@
}
for (;;) {
- gch = getchar()&STRIP_PAR;
+ gch = xgetchar();
if ((gch == character(value(ESCAPE))) && bol) {
if (!(gch = escape()))
continue;
@@ -365,7 +381,7 @@
(void)printf("%s\n", gch == '\r' ? "\r" : "");
continue;
} else if (!cumode && gch && gch == character(value(FORCE)))
- gch = getchar()&STRIP_PAR;
+ gch = xgetchar();
bol = any(gch, value(EOL));
if (boolean(value(RAISE)) && islower((unsigned char)gch))
gch = toupper((unsigned char)gch);
@@ -386,7 +402,7 @@
esctable_t *p;
char c = character(value(ESCAPE));
- gch = (getchar()&STRIP_PAR);
+ gch = xgetchar();
for (p = etable; p->e_char; p++)
if (p->e_char == gch) {
if ((p->e_flags&PRIV) && uid)
Home |
Main Index |
Thread Index |
Old Index