Closed OznOg closed 2 years ago
updated te commit with the NULL instead of nullptr
Any update on the subject? do you want me to test any other solution?
ping
ping @artyom-beilis @jwakely @Flamefire anyone review and merge this PR?
At this point I'd just say: If the string is empty return the empty tmp
at https://github.com/boostorg/locale/pull/60/files#diff-6b6b0b450f26c89b0a6d407203b2b8cea9c6e661417786980726feed67fb3fa5R93. Avoids this whole issue.
Edit: Scratch that:
Sort key byte arrays are zero-terminated and can be compared using strcmp().
I.e. the result is always at least 1 byte. Opened https://github.com/boostorg/locale/pull/72 for a better fix.
Superseded by #72 which also fixes the bug. Thanks for the report and PR!
Trying to access tmp[0] causes a crash on Fedora when assertion on STL are enabled.
/usr/include/c++/10/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = unsigned char; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.
This patch just passes nullptr as pointer to getSortKey() when tmp size is 0, preventing dereferencing elements in empty vector.
I guess that &tmp[0] should be optimized as 'no real access' when disabling assertion, but actually leads to crash when assert are enabled.