mcy / best

The Best Library: a C++ STL replacement
Apache License 2.0
165 stars 2 forks source link

Make tests pass under `-c opt` #24

Closed mcy closed 4 months ago

mcy commented 4 months ago

Make everything pass with optimizations turned on. This revealed two UB bugs:

  1. best::vec<T> was manipulating size_ directly, even when this would violate strict aliasing. This caused some tests to fail because loading size_ would ignore stores made through data(), because &size_ and data() cannot alias because they have different types. size_ is now manipulated exclusively through memcpy().

  2. A UAF in fnref_test.cc (but not best::fnref itself).

Since I was already touching best::fnref, I added a small optimization when constructing a best::fnref from a no-capture lambda.