Subject: Re: Bluetooth protocol code
To: None <tech-kern@netbsd.org>
From: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
List: tech-kern
Date: 12/20/2005 09:38:58
On Mon, Dec 19, 2005 at 11:52:22 -0800, Bill Studenmund wrote:

> > > 1) please use ANSI function declarations;
> > 
> > on all functions? (grumble grumble..)
> 
> The problem is that K&R prototypes won't work right if we pass in a 
> parameter that's larger than an int. Like a long or a pointer on an LP64 
> system.
> 
> In such a case, the caller will turn the parameter into an int, truncating 
> it. Worse yet, the caller will then pack other parameters in, not leaving 
> enough space for what the caller will expect the parameter to be. Thus the 
> callee will see two parameters mixed together in what it thinks is one 
> parameter (by our style guide, it will get the parameters right), and a 
> parameter at the end will be totally uninitialized.
> 
> This behavior is why we're moving away from K&R parameters & prototypes.

Disclaimer: I haven't had my coffee yet.

I think you are confusing it with a different issue.

What you describe would happen if there's no prototype in scope, which
is impossible in our code, as we compile with a set of options that
mandates prototypes.

The issue can arise with short integral types that are passed "as-is"
for ANSI, and that are subject to widening conversion for K&R.  To hit
this bug, you also need to be on a platform, that passes e.g. shorts
and ints diffrently, i.e. it should pass them via stack, and should
not perform the widening *always* (as e.g. i386 does).

SY, Uwe
-- 
uwe@ptc.spbu.ru                         |       Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/          |       Ist zu Grunde gehen