|
|
9c13a0 |
From daf4ef50c88c2b9a6bf2c40b537eebc202caad6e Mon Sep 17 00:00:00 2001
|
|
|
9c13a0 |
From: =?UTF-8?q?S=C3=A9bastien=20Gonzalve?=
|
|
|
9c13a0 |
<sebastien.gonzalve@aliceadsl.fr>
|
|
|
9c13a0 |
Date: Sat, 14 Nov 2020 10:39:47 +0100
|
|
|
9c13a0 |
Subject: [PATCH] Do not try to access element when vector is empty
|
|
|
9c13a0 |
|
|
|
9c13a0 |
Trying to access tmp[0] causes a crash on Fedora when assertion on STL
|
|
|
9c13a0 |
are enabled.
|
|
|
9c13a0 |
|
|
|
9c13a0 |
/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.
|
|
|
9c13a0 |
|
|
|
9c13a0 |
This patch just passes nullptr as pointer to getSortKey() when tmp size
|
|
|
9c13a0 |
is 0, preventing dereferencing elements in empty vector.
|
|
|
9c13a0 |
|
|
|
9c13a0 |
I guess that &tmp[0] should be optimized as 'no real access' when
|
|
|
9c13a0 |
disabling assertion, but actually leads to crash when assert are
|
|
|
9c13a0 |
enabled.
|
|
|
9c13a0 |
---
|
|
|
9c13a0 |
src/icu/collator.cpp | 2 +-
|
|
|
9c13a0 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
9c13a0 |
|
|
|
9c13a0 |
diff --git a/libs/locale/src/icu/collator.cpp b/libs/locale/src/icu/collator.cpp
|
|
|
9c13a0 |
index 7f1ea6a..dc59e8c 100644
|
|
|
9c13a0 |
--- a/libs/locale/src/icu/collator.cpp
|
|
|
9c13a0 |
+++ b/libs/locale/src/icu/collator.cpp
|
|
|
9c13a0 |
@@ -93,7 +93,7 @@ namespace boost {
|
|
|
9c13a0 |
std::vector<uint8_t> tmp;
|
|
|
9c13a0 |
tmp.resize(str.length());
|
|
|
9c13a0 |
icu::Collator *collate = get_collator(level);
|
|
|
9c13a0 |
- int len = collate->getSortKey(str,&tmp[0],tmp.size());
|
|
|
9c13a0 |
+ int len = collate->getSortKey(str,tmp.empty()?nullptr:&tmp[0],tmp.size());
|
|
|
9c13a0 |
if(len > int(tmp.size())) {
|
|
|
9c13a0 |
tmp.resize(len);
|
|
|
9c13a0 |
collate->getSortKey(str,&tmp[0],tmp.size());
|
|
|
9c13a0 |
--
|
|
|
9c13a0 |
2.26.2
|
|
|
9c13a0 |
|