fd_isset() undefined left shift of signed integer?
fd_isset() undefined left shift of signed integer?
- Subject: fd_isset() undefined left shift of signed integer?
- From: Sean McBride <email@hidden>
- Date: Tue, 04 Jun 2013 15:42:57 -0400
- Organization: Rogue Research Inc.
Hi all,
When running the unit tests of an open source project, clang's undefined behaviour sanitizer (ubsan) reports:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/sys/_structs.h:193:48: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
In _structs.h (OS 10.8.3 / Xcode 4.6.2) we find:
#define __DARWIN_NBBY 8 /* bits in a byte */
#define __DARWIN_NFDBITS (sizeof(__int32_t) * __DARWIN_NBBY) /* bits per mask */
190 static __inline int
191 __darwin_fd_isset(int _n, const struct fd_set *_p)
192 {
193 return (_p->fds_bits[_n/__DARWIN_NFDBITS] & (1<<(_n % __DARWIN_NFDBITS)));
194 }
_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...
Thanks,
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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