Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Dec 2005 00:45:18 +0200
From:      Ruslan Ermilov <ru@FreeBSD.org>
To:        current@FreeBSD.org
Subject:   Beware of subtle bugs due to cpp(1) limitations!
Message-ID:  <20051203224518.GJ960@ip.net.ua>

next in thread | raw e-mail | index | archive | help

--vbzKE9fGfpHIBC6T
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi there,

cpp(1) only supports integer expressions, so the following

#define	FOO	foo
#if FOO =3D=3D bar

will always evaluate to true, because "foo" and "bar" will
be treated as zeroes, as explained in cpp.info.

I've only scanned for _MACHINE_ARCH, because that's how I
discovered it, and there's a couple of places where the
code is broken:

sys/dev/isp/isp_freebsd.h:#if   _MACHINE_ARCH =3D=3D sparc64
sys/dev/ispfw/ispfw.c:#if       _MACHINE_ARCH =3D=3D sparc64
sys/dev/ispfw/ispfw.c:#if       _MACHINE_ARCH =3D=3D sparc64
sys/dev/ispfw/ispfw.c:#if       _MACHINE_ARCH =3D=3D sparc64
sys/gnu/fs/reiserfs/reiserfs_fs.h:#if (_MACHINE_ARCH =3D=3D amd64)
sys/netgraph/ng_vjc.c:#if _MACHINE_ARCH =3D=3D i386
sys/netgraph/ng_vjc.c:#elif _MACHINE_ARCH =3D=3D alpha
sys/netgraph/ng_vjc.c:#error Unspported _MACHINE_ARCH

In these cases, the right tests would be #ifdef __sparc64__.
Other instances (of not _MACHINE_ARCH) may be harder to
fix.  The ng_vjc.c is a nice example that clearly
demonstrates (without compiling the code) that it's
broken -- it's compiled on all architectures, but has
the following code:

#if _MACHINE_ARCH =3D=3D i386
#define NG_VJC_TSTATE_PTR_TYPE  &ng_parse_uint32_type
#elif _MACHINE_ARCH =3D=3D alpha
#define NG_VJC_TSTATE_PTR_TYPE  &ng_parse_uint64_type
#else
#error Unspported _MACHINE_ARCH
#endif

The season for more bugs of this type is declared open!  :-)


Cheers,
--=20
Ruslan Ermilov
ru@FreeBSD.org
FreeBSD committer

--vbzKE9fGfpHIBC6T
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFDkh/+qRfpzJluFF4RAsuQAJ409WxCpqOhYfOCaOtDp2mKX3a54wCeOj1A
lcbvVVME7PjIrinGnefue0A=
=suSU
-----END PGP SIGNATURE-----

--vbzKE9fGfpHIBC6T--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051203224518.GJ960>