fd_isset() undefined left shift of signed integer?
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 sean@rogue-research.com 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 (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.app... This email sent to site_archiver@lists.apple.com
participants (1)
-
Sean McBride