[PATCH] D40743: Make rehash(0) work with ubsan's unsigned-integer-overflow.
    Dan Albert via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Mon Jan  8 13:53:20 PST 2018
    
    
  
danalbert added inline comments.
================
Comment at: include/__hash_table:2141
         __n = 2;
     else if (__n & (__n - 1))
         __n = __next_prime(__n);
----------------
mclow.lists wrote:
> danalbert wrote:
> > With `rehash(0)` this is `0 & (0 - 1)`, which triggers unsigned-integer-overflow.
> Grumble, grumble. That's not UB, that's just UBSan whining.
> On the other hand, this doesn't appear to change any behavior, and shuts UBSan up.
FWIW, this check isn't enabled in ubsan by default. Android uses it for testing and mititgation in a handful of projects because it does catch errors (stagefright was an unsigned overflow issue). It's good to keep the libc++ headers clean of these issues so we're not dictating the compile flags of libc++ users.
Repository:
  rCXX libc++
https://reviews.llvm.org/D40743
    
    
More information about the cfe-commits
mailing list