aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/AutoComplete.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-03-29 09:03:04 +1100
committerNeil <nyamatongwe@gmail.com>2021-03-29 09:03:04 +1100
commitf1ad63380ea954ae42c26d0a4fc0e46574cd9e5f (patch)
treed0b95dd1e509cc0eca7a353520e9c409c0497195 /src/AutoComplete.cxx
parentab70e1041cb40c9d807a18ca7abb5c000adf2fdf (diff)
downloadscintilla-mirror-f1ad63380ea954ae42c26d0a4fc0e46574cd9e5f.tar.gz
Modify ListBox::GetValue to return a std::string to avoid fixed size buffers
and the possibility of truncation.
Diffstat (limited to 'src/AutoComplete.cxx')
-rw-r--r--src/AutoComplete.cxx30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx
index c3ebd9c46..779d34965 100644
--- a/src/AutoComplete.cxx
+++ b/src/AutoComplete.cxx
@@ -197,9 +197,7 @@ int AutoComplete::GetSelection() const {
}
std::string AutoComplete::GetValue(int item) const {
- char value[maxItemLen];
- lb->GetValue(item, value, sizeof(value));
- return std::string(value);
+ return lb->GetValue(item);
}
void AutoComplete::Show(bool show) {
@@ -235,21 +233,20 @@ void AutoComplete::Select(const char *word) {
int end = lb->Length() - 1; // upper bound of the api array block to search
while ((start <= end) && (location == -1)) { // Binary searching loop
int pivot = (start + end) / 2;
- char item[maxItemLen];
- lb->GetValue(sortMatrix[pivot], item, maxItemLen);
+ std::string item = GetValue(sortMatrix[pivot]);
int cond;
if (ignoreCase)
- cond = CompareNCaseInsensitive(word, item, lenWord);
+ cond = CompareNCaseInsensitive(word, item.c_str(), lenWord);
else
- cond = strncmp(word, item, lenWord);
+ cond = strncmp(word, item.c_str(), lenWord);
if (!cond) {
// Find first match
while (pivot > start) {
- lb->GetValue(sortMatrix[pivot-1], item, maxItemLen);
+ item = lb->GetValue(sortMatrix[pivot-1]);
if (ignoreCase)
- cond = CompareNCaseInsensitive(word, item, lenWord);
+ cond = CompareNCaseInsensitive(word, item.c_str(), lenWord);
else
- cond = strncmp(word, item, lenWord);
+ cond = strncmp(word, item.c_str(), lenWord);
if (0 != cond)
break;
--pivot;
@@ -259,12 +256,12 @@ void AutoComplete::Select(const char *word) {
&& ignoreCaseBehaviour == SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE) {
// Check for exact-case match
for (; pivot <= end; pivot++) {
- lb->GetValue(sortMatrix[pivot], item, maxItemLen);
- if (!strncmp(word, item, lenWord)) {
+ item = lb->GetValue(sortMatrix[pivot]);
+ if (!strncmp(word, item.c_str(), lenWord)) {
location = pivot;
break;
}
- if (CompareNCaseInsensitive(word, item, lenWord))
+ if (CompareNCaseInsensitive(word, item.c_str(), lenWord))
break;
}
}
@@ -282,12 +279,11 @@ void AutoComplete::Select(const char *word) {
} else {
if (autoSort == SC_ORDER_CUSTOM) {
// Check for a logically earlier match
- char item[maxItemLen];
for (int i = location + 1; i <= end; ++i) {
- lb->GetValue(sortMatrix[i], item, maxItemLen);
- if (CompareNCaseInsensitive(word, item, lenWord))
+ std::string item = lb->GetValue(sortMatrix[i]);
+ if (CompareNCaseInsensitive(word, item.c_str(), lenWord))
break;
- if (sortMatrix[i] < sortMatrix[location] && !strncmp(word, item, lenWord))
+ if (sortMatrix[i] < sortMatrix[location] && !strncmp(word, item.c_str(), lenWord))
location = i;
}
}