Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site talcott.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!kendall From: kendall@talcott.UUCP (Sam Kendall) Newsgroups: net.bugs.4bsd Subject: cpp bug, #line does not reset cpp's own idea of the line number Message-ID: <425@talcott.UUCP> Date: Wed, 1-May-85 20:52:29 EDT Article-I.D.: talcott.425 Posted: Wed May 1 20:52:29 1985 Date-Received: Fri, 3-May-85 04:29:42 EDT Distribution: net Organization: Delft Consulting Corp., New York Lines: 86 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); }