Re: Beware of subtle bugs due to cpp(1) limitations!

From: Ruslan Ermilov <ru_at_FreeBSD.org>
Date: Sun, 4 Dec 2005 01:04:31 +0200
On Sun, Dec 04, 2005 at 12:55:17AM +0200, Ruslan Ermilov wrote:
> On Sun, Dec 04, 2005 at 12:45:18AM +0200, Ruslan Ermilov wrote:
> > Hi there,
> > 
> > cpp(1) only supports integer expressions, so the following
> > 
> > #define	FOO	foo
> > #if FOO == bar
> > 
> > will always evaluate to true, because "foo" and "bar" will
> > be treated as zeroes, as explained in cpp.info.
[...]
> > The season for more bugs of this type is declared open!  :-)
> > 
> ``cpp -Wundef'' will allow us to find all these bugs.
> 
Here we go:

%%%
Index: share/mk/bsd.sys.mk
===================================================================
RCS file: /home/ncvs/src/share/mk/bsd.sys.mk,v
retrieving revision 1.37
diff -u -r1.37 bsd.sys.mk
--- share/mk/bsd.sys.mk	16 Jan 2005 21:18:16 -0000	1.37
+++ share/mk/bsd.sys.mk	3 Dec 2005 22:57:36 -0000
_at__at_ -11,7 +11,7 _at__at_
 .if !defined(NO_WARNS) && ${CC} != "icc"
 . if defined(WARNS)
 .  if ${WARNS} >= 1
-CWARNFLAGS	+=	-Wsystem-headers
+CWARNFLAGS	+=	-Wsystem-headers -Wundef
 .   if !defined(NO_WERROR)
 CWARNFLAGS	+=	-Werror
 .   endif
Index: sys/conf/kern.mk
===================================================================
RCS file: /home/ncvs/src/sys/conf/kern.mk,v
retrieving revision 1.46
diff -u -r1.46 kern.mk
--- sys/conf/kern.mk	15 Jul 2005 11:45:30 -0000	1.46
+++ sys/conf/kern.mk	3 Dec 2005 22:58:41 -0000
_at__at_ -12,7 +12,7 _at__at_
 .else
 CWARNFLAGS?=	-Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
 		-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
-		-fformat-extensions -std=c99
+		-Wundef -fformat-extensions -std=c99
 .endif
 #
 # The following flags are next up for working on:
%%%

Should I commit it to force a thorough fixing?
(The #ifdef notdef/notyet are not affected by this change.)


Cheers,
-- 
Ruslan Ermilov
ru_at_FreeBSD.org
FreeBSD committer

Received on Sat Dec 03 2005 - 22:06:12 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:48 UTC