Bug in C Preprocessr
Aryeh M. Weiss
aryeh at eddie.MIT.EDU
Sun Sep 17 22:59:08 AEST 1989
This is a beezarr one gang! Listen and attend:
Machine: 16 MHz 386/387 Hauppauge motherboard w/ 1MB. Total mem: 5MB
Op Sys: SCO Xenix V/386 R2.3.1
Dev Sys: SCO Xenix V/386 R2.3
I was porting Gnu Bison v1.03 to the above machine when the compile bombed
out on one of the modules. I looked at the code and decided (in a flash
of insight like a diamond bullet in my brain) that the preprocessor screwed
up. I looked at the prepocessor output (ie. "cc -DUSG -P closure.c") and was
amazed that a #define got expanded wrong! Below is a program that
reproduces the error. WORDSIZE(n) gets expanded as
(((n) + 32 - 1) 32)
That's right: no slash before the final 32. THIS IS THE BEZARR PART: if I
change just ONE character in the big comment at the beginning of the file,
that is, I delete OR add a character in the comment OR if I delete one of
the blank lines the WORDSIZE macro is expanded correctly! The only
explanation I have is that some buffer in cpp is being overrun, but that
doesn't explain everything.
#! /bin/sh
# To extract, remove mail header lines and type "sh filename"
# DO NOT CHANGE ANYTHING IN THIS FILE BEFORE YOU TRY TO REPRODUCE THE ERROR
# Preprocess file via cc -P xxx.c
echo x - xxx.c
sed -e 's/^X//' > xxx.c << '!FaR!OuT!'
X/* Define machine-dependencies for bison,
X Copyright (C) 1984, 1989 Free Software Foundation, Inc.
X
XThis file is part of Bison, the GNU Compiler Compiler.
X
XBison is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation; either version 1, or (at your option)
Xany later version.
X
XBison is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
XGNU General Public License for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with Bison; see the file COPYING. If not, write to
Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
X
X
X#define MAXSHORT 32767
X#define MINSHORT -32768
X
X#ifdef MSDOS
X#define MAXTABLE 16383
X#define BITS_PER_WORD 16
X#else
X#define MAXTABLE 32767
X#define BITS_PER_WORD 32
X#endif
X
X#define WORDSIZE(n) (((n) + BITS_PER_WORD - 1) / BITS_PER_WORD)
X
X WORDSIZE(n)
!FaR!OuT!
exit
--
aryeh at eddie.mit.edu
mit-eddie!lees-rif!aryeh
More information about the Comp.unix.xenix
mailing list