Re: FROMBCD coding style flaw

Reinoud Zandijk <[email protected]>
Newsgroups gmane.os.netbsd.ports.prep,gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
On Sun, Nov 20, 2005 at 05:44:31PM +0100, Martin Husemann wrote:
> On Sun, Nov 20, 2005 at 04:16:41PM +0100, Anders Gavare wrote:
> > Basically, the FROMBCD macro is misused if it is given a function call
> > as an argument, instead of a plain variable.
> 
> Maybe we could define a different version for DIAGNOSTIC or DEBUG kernels
> that takes the address of the arg, so it fails compilation for the broken
> usage - something like this (untested):
> 
> #if defined(__GNUC__) && defined(DIAGNOSTIC)
> #define     FROMBCD(x)      ({				\
> 		__typeof(x) *v = &x;			\
> 		(((*v) >> 4) * 10 + ((*v) & 0xf));	\
> 	}
> #else
> #define     FROMBCD(x)      (((x) >> 4) * 10 + ((x) & 0xf))
> #endif

Or maybe just create a small inline function?

Reinoud
signature.asc (application/pgp-signature, 478 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (NetBSD)

iQEVAwUBQ7Gg8oKcNwBDyKpoAQKNuAf/XxPYysqnTow/97vayxPAulMxfjmvs/0y
ll8nlVSqzBdefZKHiuWlhI8gXKCK9uuj/vsnVM/PeuXVyda8uB1c7GoUlh/5rob+
kD4Kkva8IjemLEpPxNkIThJcwf6VGv6jq+o666nEKYPclIb9VqJlU+Q//ONJDtD9
MiFvf9JvTn6F47N6WxjFeyDkRadhVA1Nkc0kwpbePtLEMi1qObwtpByPCYhXkxmg
nD4qExEl0WQu10vKGTFsks5TVNy/KTFuxEDksK64cmpIPg8kgtYjypKsnObrkL8O
Em5Um9HUu/6U6O4n98PkzFHIs7TnfUVR4MEyyuXb5k0lqwYEtc/NlQ==
=3xl8
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.