34 lines
1.8 KiB
Diff
34 lines
1.8 KiB
Diff
From 1ff0ead837b32b9415dc840dfef6549e8754b98d Mon Sep 17 00:00:00 2001
|
|
From: Alexander Grund <Flamefire@users.noreply.github.com>
|
|
Date: Fri, 10 Dec 2021 17:53:01 +0100
|
|
Subject: [PATCH] Fix access to first element of empty vector
|
|
|
|
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<unsigned char>; std::vector<_Tp, _Alloc>::reference = unsigned char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.
|
|
|
|
Fix is to never have an empty vector as ICU sort keys include the NULL
|
|
terminator, hence we need at least `length + 1` bytes which means the
|
|
vector has at least 1 element: The NULL terminator
|
|
---
|
|
src/icu/collator.cpp | 4 ++--
|
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/libs/locale/src/icu/collator.cpp b/libs/locale/src/icu/collator.cpp
|
|
index 7f1ea6ae..79668aa6 100644
|
|
--- a/libs/locale/src/icu/collator.cpp
|
|
+++ b/libs/locale/src/icu/collator.cpp
|
|
@@ -91,9 +91,9 @@ namespace boost {
|
|
{
|
|
icu::UnicodeString str=cvt_.icu(b,e);
|
|
std::vector<uint8_t> tmp;
|
|
- tmp.resize(str.length());
|
|
+ tmp.resize(str.length() + 1u);
|
|
icu::Collator *collate = get_collator(level);
|
|
- int len = collate->getSortKey(str,&tmp[0],tmp.size());
|
|
+ const int len = collate->getSortKey(str,&tmp[0],tmp.size());
|
|
if(len > int(tmp.size())) {
|
|
tmp.resize(len);
|
|
collate->getSortKey(str,&tmp[0],tmp.size());
|