ecmwf / magics

Plotting package to visualise meteorological data in GRIB, NetCDF, BUFR and ODB format.
Apache License 2.0
56 stars 15 forks source link

Fix empty vector access errors when _GLIBCXX_ASSERTIONS is set (SD-80581) #101

Open edigiacomo opened 1 year ago

edigiacomo commented 1 year ago

When _GLIBCXX_ASSERTIONS is set (see https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html), Magics sometimes throws a runtime error:

/usr/include/c++/12/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = double; _Alloc = std::allocator<double>; reference = double&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

The runtime error are raised when some instance methods are invoked on an empty vector, e.g. operator[] or front(). This PR tries to fix some of these potential errors, resizing the vector before populating it or using insert instead of operator[].

See https://jira.ecmwf.int/plugins/servlet/desk/portal/4/SD-80581 for more details.

FussyDuck commented 1 year ago

CLA assistant check
All committers have signed the CLA.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information