Re: fd_isset() undefined left shift of signed integer?
Re: fd_isset() undefined left shift of signed integer?
- Subject: Re: fd_isset() undefined left shift of signed integer?
- From: Stephen Checkoway <email@hidden>
- Date: Tue, 04 Jun 2013 20:57:28 -0400
On Jun 4, 2013, at 3:42 PM, Sean McBride <email@hidden> wrote:
> _n % 32 will sometimes give 31, and 1<<31 pushes a 1 into the sign bit, which is undefined.
>
> Do you agree that __darwin_fd_isset is buggy? Just wanted to check before filing a Radar...
A quick look at the C99 spec (specifically, 6.5.7 Bitwise shift operators) indicates that it is indeed buggy (in the sense that it is undefined, almost certainly not in the sense that it'll do the wrong thing on any architecture that Apple cares about).
"The result of E1 << E2 is E1 left-shifted E2 bit positions[...] If E1 has a signed type and nonnegative value, and E1 * 2^{E2} is representable in the result type, then that is the resulting value; otherwise, the behavior is undefined."
--
Stephen Checkoway
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden