gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

SmallVector: Make destructor more robust #93

Closed Finii closed 3 months ago

Finii commented 3 months ago

[why] When the library is compiled with heavy instrumentalization (e.g. gcov) in some cases we get this compiler warning:

include/gul14/SmallVector.h:426:13: warning: ‘void operator delete [](void*)’ called on unallocated object ‘v3’ [-Wfree-nonheap-object]
  426 |             delete[] data_ptr_;
      |             ^~~~~~~~~~~~~~~~~~

The problem is the detection if the thing that currently holds the data is allocated or not. At the moment the size (capacity) is used as indirect marker. It seems that this can go wrong.

[how] Use instead the pointed to address directly. We know the address of the internal data-holding array, and when the current data is not THAT is must be allocated.

Fixes: #91

Reviewed-by: Soeren Grunewald soeren.grunewald@desy.de