cpp bug, #line does not reset cpp's own idea of the line number
Sam Kendall
kendall at talcott.UUCP
Thu May 2 10:52:29 AEST 1985
Index: lib/cpp/cpp.c 4.2BSD
Description:
#line directives to the C preprocessor are passed through to
the compiler proper, but they should also be remembered by the
preprocessor. Currently the preprocessor remembers the file
name that #line gives, but not the line number. This can
confuse error messages and dbx(1) about line numbers,
particularly on files produced by preprocessors such as
yacc(1). (This problem is fixed in SysV; V7 cpp's remember
neither the line number nor the filename.)
There are two other, much less serious problems with
"cpp.c". First, it is missing external function declarations;
and second, one part of code performs a pointer subtraction
with the right operand sometimes null; this is not legal C,
although the code happens to work on most machines.
Repeat-By:
Type to the shell
$ /lib/cpp
#line 999 "wombat.c"
__LINE__ __FILE__
The cpp's last line in response will be
2 "wombat.c"
But it should be
999 "wombat.c"
Fix:
There are three changes to "cpp.c". The first adds external
function declarations; the second makes #line reset the line
number; and the third fixes the piece of code the does a
pointer subtraction with a null right operand.
*** old/cpp.c Thu Apr 11 12:47:18 1985
--- cpp.c Thu Apr 11 12:55:12 1985
***************
*** 10,15
# include "stdio.h"
# include "ctype.h"
/* C command
/* written by John F. Reiser
/* July/August 1978
--- 10,17 -----
# include "stdio.h"
# include "ctype.h"
+ extern char *calloc(), *strcat(), *strcpy(), *rindex();
+
/* C command
/* written by John F. Reiser
/* July/August 1978
***************
*** 760,765
cp = outp + 1;
while (isspace(*cp) && cp < inp)
cp++;
while (isdigit(*cp) && cp < inp)
cp++;
while (*cp != '"' && cp < inp)
--- 762,768 -----
cp = outp + 1;
while (isspace(*cp) && cp < inp)
cp++;
+ lineno[ifno] = atoi(cp); /* reset __LINE__ */
while (isdigit(*cp) && cp < inp)
cp++;
while (*cp != '"' && cp < inp)
***************
*** 891,897
int nlines = 0;
if (0==(vp=sp->value)) return(p);
! if ((p-macforw)<=macdam) {
if (++maclvl>symsiz && !rflag) {
pperror("%s: macro recursion",sp->name); return(p);
}
--- 894,900 -----
int nlines = 0;
if (0==(vp=sp->value)) return(p);
! if (macforw!=NULL && (p-macforw)<=macdam) {
if (++maclvl>symsiz && !rflag) {
pperror("%s: macro recursion",sp->name); return(p);
}
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list