Beware of subtle bugs due to cpp(1) limitations!
Ruslan Ermilov
ru at FreeBSD.org
Sat Dec 3 14:55:56 PST 2005
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.
>
> 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 == sparc64
> sys/dev/ispfw/ispfw.c:#if _MACHINE_ARCH == sparc64
> sys/dev/ispfw/ispfw.c:#if _MACHINE_ARCH == sparc64
> sys/dev/ispfw/ispfw.c:#if _MACHINE_ARCH == sparc64
> sys/gnu/fs/reiserfs/reiserfs_fs.h:#if (_MACHINE_ARCH == amd64)
> sys/netgraph/ng_vjc.c:#if _MACHINE_ARCH == i386
> sys/netgraph/ng_vjc.c:#elif _MACHINE_ARCH == 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 == i386
> #define NG_VJC_TSTATE_PTR_TYPE &ng_parse_uint32_type
> #elif _MACHINE_ARCH == 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! :-)
>
``cpp -Wundef'' will allow us to find all these bugs.
Cheers,
--
Ruslan Ermilov
ru at FreeBSD.org
FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20051204/3314e5eb/attachment.bin
More information about the freebsd-current
mailing list