fix an inconsistency between signed- and unsigned-char machines:

make sure that pushed-back 0xff character isn't accidentally
interpreted as an EOF because of sign extension when chars were being
assigned to pbents.  (signed-char machines lost.)  To do this, make
putback() and pbstr() operate only on unsigned chars, and add a
putbackeof() function to do the obvious thing when necessary.
This commit is contained in:
cgd 1997-12-29 19:52:55 +00:00
parent d5f6b80949
commit 86cd94fb5a
3 changed files with 21 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.5 1997/12/02 22:34:00 cgd Exp $ */
/* $NetBSD: extern.h,v 1.6 1997/12/29 19:52:55 cgd Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -68,6 +68,7 @@ void onintr __P((int));
void pbnum __P((int));
void pbstr __P((char *));
void putback __P((int));
void putbackeof __P((void));
void remhash __P((char *, int));
void usage __P((void));

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.14 1997/12/02 22:34:02 cgd Exp $ */
/* $NetBSD: main.c,v 1.15 1997/12/29 19:52:56 cgd Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: main.c,v 1.14 1997/12/02 22:34:02 cgd Exp $");
__RCSID("$NetBSD: main.c,v 1.15 1997/12/29 19:52:56 cgd Exp $");
#endif
#endif /* not lint */
@ -216,7 +216,7 @@ main(argc,argv)
if (*m4wraps) { /* anything for rundown ?? */
ilevel = 0; /* in case m4wrap includes.. */
bufbase = bp = buf; /* use the entire buffer */
putback(EOF); /* eof is a must !! */
putbackeof(); /* eof is a must !! */
pbstr(m4wraps); /* user-defined wrapup act */
macro(); /* last will and testament */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: misc.c,v 1.8 1997/12/02 22:34:05 cgd Exp $ */
/* $NetBSD: misc.c,v 1.9 1997/12/29 19:52:57 cgd Exp $ */
/*
* Copyright (c) 1989, 1993
@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: misc.c,v 1.8 1997/12/02 22:34:05 cgd Exp $");
__RCSID("$NetBSD: misc.c,v 1.9 1997/12/29 19:52:57 cgd Exp $");
#endif
#endif /* not lint */
@ -78,7 +78,7 @@ indx(s1, s2)
*/
void
putback(c)
pbent c;
unsigned char c;
{
if (bp < endpbb)
*bp++ = c;
@ -86,6 +86,18 @@ putback(c)
errx(1, "too many characters pushed back");
}
/*
* putbackeof - push EOF back onto input
*/
void
putbackeof()
{
if (bp < endpbb)
*bp++ = EOF;
else
errx(1, "too many characters pushed back");
}
/*
* pbstr - push string back onto input
* putback is replicated to improve
@ -106,7 +118,7 @@ pbstr(s)
es--;
while (es >= s)
if (zp < endpbb)
*zp++ = *es--;
*zp++ = (unsigned char)*es--;
if ((bp = zp) == endpbb)
errx(1, "too many characters pushed back");
}