[llvm] r292575 - BitVector: Fix undefined behaviour

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 09:47:42 PST 2017


I realize it's UB, so not exactly testable - but a unit test that exercises
this (& that, say, asan would have failed on without the fix) would be good.

On Thu, Jan 19, 2017 at 8:34 PM Matthias Braun via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: matze
> Date: Thu Jan 19 22:23:08 2017
> New Revision: 292575
>
> URL: http://llvm.org/viewvc/llvm-project?rev=292575&view=rev
> Log:
> BitVector: Fix undefined behaviour
>
> Calling reset() on an empty BitVector would call memset with a nullptr
> argument which is undefined behaviour.
>
> This should fix the sanitizer bot.
>
> Modified:
>     llvm/trunk/include/llvm/ADT/BitVector.h
>
> Modified: llvm/trunk/include/llvm/ADT/BitVector.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=292575&r1=292574&r2=292575&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/BitVector.h (original)
> +++ llvm/trunk/include/llvm/ADT/BitVector.h Thu Jan 19 22:23:08 2017
> @@ -539,7 +539,8 @@ private:
>    }
>
>    void init_words(BitWord *B, unsigned NumWords, bool t) {
> -    memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
> +    if (NumWords > 0)
> +      memset(B, 0 - (int)t, NumWords*sizeof(BitWord));
>    }
>
>    template<bool AddBits, bool InvertMask>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170123/a4a4676f/attachment.html>


More information about the llvm-commits mailing list