Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM)

Steve Kargl sgk at troutmask.apl.washington.edu
Tue Jan 1 05:52:30 UTC 2019


On Tue, Jan 01, 2019 at 12:14:38AM -0500, Pedro Giffuni wrote:
> 
> > I'll defer to Bruce on this.  My only comments are
> > 1) declarations belong at the top of the file where all declarations occur
> 
> Modern standards let you declare variables within blocks. For style we 
> do prefer to start the function with them but in this case we can't.

I'am aware of what modern standards allow.  I'm also
aware of the code style of fdlibm, which I think 
should be maintain.

> > 2) j is already declared as int32_t
> And it has to be a signed integer: we later check for negative values.

Yeah, I know.  That's why I pointed out the collision.

> > 3) uint32_t should be written as u_int32_t.
> 
> No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the file 
> consistently uses uint32_t.

Ah, no.  e_pow.c uses u_int32_t on line 107.  This would be easy
to see if all declarations are grouped together.   In additional,
don't you need to include stdint.h to get uint32_t?

% grep uint32_t /usr/src/lib/msun/src/e_pow.c
% grep u_int32_t /usr/src/lib/msun/src/e_pow.c
        u_int32_t lx,ly;
        n = ((u_int32_t)hx>>31)-1;

Code churn to placate lint for an event that cannot occur
seems dubious to me.

-- 
Steve


More information about the freebsd-numerics mailing list