Subject: Re: FROMBCD coding style flaw
To: Martin Husemann <martin@duskware.de>
From: Reinoud Zandijk <reinoud@netbsd.org>
List: port-prep
Date: 12/27/2005 21:15:54
--qDbXVdCdHGoSgWSk
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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

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

-----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-----

--qDbXVdCdHGoSgWSk--