diff options
-rw-r--r-- | cocoa/PlatCocoa.mm | 11 | ||||
-rwxr-xr-x | gtk/PlatGTK.cxx | 12 | ||||
-rw-r--r-- | qt/ScintillaEditBase/PlatQt.cpp | 8 | ||||
-rw-r--r-- | src/AutoComplete.cxx | 30 | ||||
-rw-r--r-- | src/Platform.h | 2 | ||||
-rw-r--r-- | win32/PlatWin.cxx | 7 |
6 files changed, 31 insertions, 39 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index bec70e8b9..af420c47b 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -1923,7 +1923,7 @@ public: void Select(int n) override; int GetSelection() override; int Find(const char *prefix) override; - void GetValue(int n, char *value, int len) override; + std::string GetValue(int n) override; void RegisterImage(int type, const char *xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; void ClearRegisteredImages() override; @@ -2145,13 +2145,12 @@ int ListBoxImpl::Find(const char *prefix) { return - 1; } -void ListBoxImpl::GetValue(int n, char *value, int len) { +std::string ListBoxImpl::GetValue(int n) { const char *textString = ld.GetString(n); - if (textString == NULL) { - value[0] = '\0'; - return; + if (textString) { + return textString; } - strlcpy(value, textString, len); + return std::string(); } void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx index a6ced568a..c71d1dff4 100755 --- a/gtk/PlatGTK.cxx +++ b/gtk/PlatGTK.cxx @@ -1394,7 +1394,7 @@ public: void Select(int n) override; int GetSelection() override; int Find(const char *prefix) override; - void GetValue(int n, char *value, int len) override; + std::string GetValue(int n) override; void RegisterRGBA(int type, std::unique_ptr<RGBAImage> image); void RegisterImage(int type, const char *xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; @@ -1961,7 +1961,7 @@ int ListBoxX::Find(const char *prefix) { return -1; } -void ListBoxX::GetValue(int n, char *value, int len) { +std::string ListBoxX::GetValue(int n) { char *text = nullptr; GtkTreeIter iter {}; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list)); @@ -1969,12 +1969,12 @@ void ListBoxX::GetValue(int n, char *value, int len) { if (valid) { gtk_tree_model_get(model, &iter, TEXT_COLUMN, &text, -1); } - if (text && len > 0) { - g_strlcpy(value, text, len); - } else { - value[0] = '\0'; + std::string value; + if (text) { + value = text; } g_free(text); + return value; } // g_return_if_fail causes unnecessary compiler warning in release compile. diff --git a/qt/ScintillaEditBase/PlatQt.cpp b/qt/ScintillaEditBase/PlatQt.cpp index ee91f8311..b9d6a0351 100644 --- a/qt/ScintillaEditBase/PlatQt.cpp +++ b/qt/ScintillaEditBase/PlatQt.cpp @@ -953,7 +953,7 @@ public: void Select(int n) override; int GetSelection() override; int Find(const char *prefix) override; - void GetValue(int n, char *value, int len) override; + std::string GetValue(int n) override; void RegisterImage(int type, const char *xpmData) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; @@ -1128,15 +1128,13 @@ int ListBoxImpl::Find(const char *prefix) return result; } -void ListBoxImpl::GetValue(int n, char *value, int len) +std::string ListBoxImpl::GetValue(int n) { ListWidget *list = GetWidget(); QListWidgetItem *item = list->item(n); QString str = item->data(Qt::DisplayRole).toString(); QByteArray bytes = unicodeMode ? str.toUtf8() : str.toLocal8Bit(); - - strncpy(value, bytes.constData(), len); - value[len-1] = '\0'; + return std::string(bytes.constData()); } void ListBoxImpl::RegisterQPixmapImage(int type, const QPixmap& pm) 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; } } diff --git a/src/Platform.h b/src/Platform.h index ffe52446c..d46f050d6 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -329,7 +329,7 @@ public: virtual void Select(int n)=0; virtual int GetSelection()=0; virtual int Find(const char *prefix)=0; - virtual void GetValue(int n, char *value, int len)=0; + virtual std::string GetValue(int n)=0; virtual void RegisterImage(int type, const char *xpm_data)=0; virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) = 0; virtual void ClearRegisteredImages()=0; diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index b2b188cb6..5e53b2888 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -2967,7 +2967,7 @@ public: void Select(int n) override; int GetSelection() override; int Find(const char *prefix) override; - void GetValue(int n, char *value, int len) override; + std::string GetValue(int n) override; void RegisterImage(int type, const char *xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; void ClearRegisteredImages() override; @@ -3122,10 +3122,9 @@ int ListBoxX::Find(const char *) { return LB_ERR; } -void ListBoxX::GetValue(int n, char *value, int len) { +std::string ListBoxX::GetValue(int n) { const ListItemData item = lti.Get(n); - strncpy(value, item.text, len); - value[len-1] = '\0'; + return item.text; } void ListBoxX::RegisterImage(int type, const char *xpm_data) { |