Page 1 of 1

Undefined behavior in topaz app

Posted: 07 Nov 2023, 16:16
by jamesjer
The Fedora project builds packages with -D_GLIBCXX_ASSERTIONS. One of the assertions failed while running the polymake 4.11 test suite. In apps/topaz/src/barycentric_subdivision.cc, line 142, description.back() is called. However, during test suite execution at least, description can be empty. Calling back() on an empty string invokes undefined behavior. Please check that description.empty() is false before calling description.back(). (And thank you again for the 4.11 release!)

Re: Undefined behavior in topaz app

Posted: 07 Nov 2023, 16:57
by blorenz
Thanks for the report, I have fixed this for our master branch.
I am slightly surprised that this did not trigger the sanitizer build in our CI, but I will check if we can add _GLIBCXX_ASSERTIONS to one of the builds.

Benjamin

Code: Select all

- if (description.back() != '\n') + if (description.empty() || description.back() != '\n')

Re: Undefined behavior in topaz app

Posted: 14 Nov 2023, 12:00
by gawrilow
We are running the sanitizer in the configuration with libc++ from LLVM, where std::string has a small internal buffer for short strings (up to 6 bytes) overlapping with the pointer to heap-allocated long strings. This way, from the low-level perspective, the last character is always well-allocated and even initialized (with 0).