diff options
author | Neil <nyamatongwe@gmail.com> | 2015-03-13 13:50:25 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-03-13 13:50:25 +1100 |
commit | 751585656e3a2ee16d28d01a732fc5ed3bd349c9 (patch) | |
tree | 8c933a36d226b6d38cbb9af935e09ce72d8ca0cc | |
parent | a3b272a89f40f8998cbb8b2637e5ed56a7d24f2d (diff) | |
download | scintilla-mirror-751585656e3a2ee16d28d01a732fc5ed3bd349c9.tar.gz |
Truncate elements that are near to maxItemLen to avoid possibility of writing
outside bounds. Also avoids warning for use of strncpy.
-rw-r--r-- | src/AutoComplete.cxx | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index d154a913a..27eed53b9 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -167,7 +167,9 @@ void AutoComplete::SetList(const char *list) { char item[maxItemLen]; for (size_t i = 0; i < sortMatrix.size(); ++i) { int wordLen = IndexSort.indices[sortMatrix[i] * 2 + 2] - IndexSort.indices[sortMatrix[i] * 2]; - strncpy(item, list + IndexSort.indices[sortMatrix[i] * 2], wordLen); + if (wordLen > maxItemLen-2) + wordLen = maxItemLen - 2; + memcpy(item, list + IndexSort.indices[sortMatrix[i] * 2], wordLen); if ((i+1) == sortMatrix.size()) { // Last item so remove separator if present if ((wordLen > 0) && (item[wordLen-1] == separator)) |