Commit b0e426fc by Antonio Maiorano

Subzero: fix Ice::BitVector::grow not copying old to new data

UBSAN pointed out that memcpy cannot have nullptr dest or source, which I've also fixed; however, this also made me realize a latent bug: the dest and source args needed to be swapped. It seems this bug hasn't bit us yet because the normal use-case is to resize the bitvector, and then call 'set' to set all bits to 0 or 1. In any case, still worth fixing. Bug: b/171581990 Change-Id: Iaaa7e019b53ae661f49c97195f2d144b5715f164 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49528 Presubmit-Ready: Antonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com>
parent 7751fe38
...@@ -768,8 +768,10 @@ private: ...@@ -768,8 +768,10 @@ private:
Capacity = std::max(NumBitWords(NewSize), Capacity * 2); Capacity = std::max(NumBitWords(NewSize), Capacity * 2);
assert(Capacity > 0 && "realloc-ing zero space"); assert(Capacity > 0 && "realloc-ing zero space");
auto *NewBits = Alloc.allocate(Capacity); auto *NewBits = Alloc.allocate(Capacity);
std::memcpy(Bits, NewBits, OldCapacity * sizeof(BitWord)); if (Bits) {
Alloc.deallocate(Bits, OldCapacity); std::memcpy(NewBits, Bits, OldCapacity * sizeof(BitWord));
Alloc.deallocate(Bits, OldCapacity);
}
Bits = NewBits; Bits = NewBits;
clear_unused_bits(); clear_unused_bits();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment