diff options
-rw-r--r-- | src/SplitVector.h | 22 | ||||
-rw-r--r-- | test/unit/testSplitVector.cxx | 104 | ||||
-rw-r--r-- | win32/SciLexer.vcxproj | 2 | ||||
-rw-r--r-- | win32/scintilla.mak | 2 |
4 files changed, 118 insertions, 12 deletions
diff --git a/src/SplitVector.h b/src/SplitVector.h index 3153700f5..df722530e 100644 --- a/src/SplitVector.h +++ b/src/SplitVector.h @@ -29,15 +29,17 @@ protected: void GapTo(int position) { if (position != part1Length) { if (position < part1Length) { - memmove( - body + position + gapLength, + // Moving the gap towards start so moving elements towards end + std::copy_backward( body + position, - sizeof(T) * (part1Length - position)); - } else { // position > part1Length - memmove( body + part1Length, + body + gapLength + part1Length); + } else { // position > part1Length + // Moving the gap towards end so moving elements towards start + std::copy( body + part1Length + gapLength, - sizeof(T) * (position - part1Length)); + body + gapLength + position, + body + part1Length); } part1Length = position; } @@ -93,7 +95,7 @@ public: GapTo(lengthBody); T *newBody = new T[newSize]; if ((size != 0) && (body != 0)) { - memmove(newBody, body, sizeof(T) * lengthBody); + std::copy(body, body + lengthBody, newBody); delete []body; } body = newBody; @@ -205,7 +207,7 @@ public: } RoomFor(insertLength); GapTo(positionToInsert); - memmove(body + part1Length, s + positionFrom, sizeof(T) * insertLength); + std::copy(s + positionFrom, s + positionFrom + insertLength, body + part1Length); lengthBody += insertLength; part1Length += insertLength; gapLength -= insertLength; @@ -254,11 +256,11 @@ public: if (range1Length > part1AfterPosition) range1Length = part1AfterPosition; } - memcpy(buffer, body + position, range1Length * sizeof(T)); + std::copy(body + position, body + position + range1Length, buffer); buffer += range1Length; position = position + range1Length + gapLength; int range2Length = retrieveLength - range1Length; - memcpy(buffer, body + position, range2Length * sizeof(T)); + std::copy(body + position, body + position + range2Length, buffer); } T *BufferPointer() { diff --git a/test/unit/testSplitVector.cxx b/test/unit/testSplitVector.cxx index a82d4491f..d71e26dd5 100644 --- a/test/unit/testSplitVector.cxx +++ b/test/unit/testSplitVector.cxx @@ -14,6 +14,18 @@ // Test SplitVector. +struct StringSetHolder { + SplitVector<std::string> sa; + bool Check() { + for (int i = 0; i < sa.Length(); i++) { + if (sa[i].empty()) { + return false; + } + } + return true; + } +}; + const int lengthTestArray = 4; static const int testArray[4] = {3, 4, 5, 6}; @@ -42,6 +54,98 @@ TEST_CASE("SplitVector") { } } + SECTION("InsertionString") { + // This test failed an earlier version of SplitVector that copied backwards incorrectly + StringSetHolder ssh; + ssh.sa.Insert(0, "Alpha"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Beta"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Cat"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Dog"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Elephant"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Fox"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Grass"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Hat"); + REQUIRE(ssh.Check()); + ssh.sa.Delete(4); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Indigo"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Jackal"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Kanga"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Lion"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(0, "Mango"); + REQUIRE(ssh.Check()); + ssh.sa.Insert(1, "Neon"); + REQUIRE(ssh.Check()); + } + + SECTION("InsertionPattern") { + sv.Insert(0, 1); // 1 + sv.Insert(0, 2); // 21 + sv.Insert(0, 3); // 321 + sv.Insert(1, 4); // 3421 + sv.Insert(0, 5); // 53421 + sv.Insert(1, 6); // 563421 + sv.Insert(0, 7); // 7563421 + sv.Insert(1, 8); // 78563421 + + REQUIRE(8 == sv.Length()); + + REQUIRE(7 == sv.ValueAt(0)); + REQUIRE(8 == sv.ValueAt(1)); + REQUIRE(5 == sv.ValueAt(2)); + REQUIRE(6 == sv.ValueAt(3)); + REQUIRE(3 == sv.ValueAt(4)); + REQUIRE(4 == sv.ValueAt(5)); + REQUIRE(2 == sv.ValueAt(6)); + REQUIRE(1 == sv.ValueAt(7)); + + sv.Delete(4); // 7856421 + + REQUIRE(7 == sv.Length()); + + REQUIRE(7 == sv.ValueAt(0)); + REQUIRE(8 == sv.ValueAt(1)); + REQUIRE(5 == sv.ValueAt(2)); + REQUIRE(6 == sv.ValueAt(3)); + REQUIRE(4 == sv.ValueAt(4)); + REQUIRE(2 == sv.ValueAt(5)); + REQUIRE(1 == sv.ValueAt(6)); + + sv.Insert(0, 9); // 97856421 + sv.Insert(1, 0xa); // 9a7856421 + sv.Insert(0, 0xb); // b9a7856421 + sv.Insert(1, 0xc); // bc9a7856421 + sv.Insert(0, 0xd); // dbc9a7856421 + sv.Insert(1, 0xe); // debc9a7856421 + + REQUIRE(13 == sv.Length()); + + REQUIRE(0xd == sv.ValueAt(0)); + REQUIRE(0xe == sv.ValueAt(1)); + REQUIRE(0xb == sv.ValueAt(2)); + REQUIRE(0xc == sv.ValueAt(3)); + REQUIRE(9 == sv.ValueAt(4)); + REQUIRE(0xa == sv.ValueAt(5)); + REQUIRE(7 == sv.ValueAt(6)); + REQUIRE(8 == sv.ValueAt(7)); + REQUIRE(5 == sv.ValueAt(8)); + REQUIRE(6 == sv.ValueAt(9)); + REQUIRE(4 == sv.ValueAt(10)); + REQUIRE(2 == sv.ValueAt(11)); + REQUIRE(1 == sv.ValueAt(12)); + } + SECTION("EnsureLength") { sv.EnsureLength(4); REQUIRE(4 == sv.Length()); diff --git a/win32/SciLexer.vcxproj b/win32/SciLexer.vcxproj index 2e821b39a..68a9e8fcd 100644 --- a/win32/SciLexer.vcxproj +++ b/win32/SciLexer.vcxproj @@ -56,7 +56,7 @@ <ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level4</WarningLevel>
- <PreprocessorDefinitions>WIN32;SCI_LEXER;_CRT_SECURE_NO_DEPRECATE;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>WIN32;SCI_LEXER;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\include;..\src;..\lexlib;</AdditionalIncludeDirectories>
<BrowseInformation>true</BrowseInformation>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
diff --git a/win32/scintilla.mak b/win32/scintilla.mak index 6a3be2564..483f78b3c 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -24,7 +24,7 @@ XP_DEFINE=-D_USING_V110_SDK71_ XP_LINK=-SUBSYSTEM:WINDOWS,5.01 !ENDIF -CRTFLAGS=-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 -D_CRT_SECURE_NO_DEPRECATE=1 $(XP_DEFINE) +CRTFLAGS=-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1 -D_CRT_SECURE_NO_DEPRECATE=1 -D_SCL_SECURE_NO_WARNINGS=1 $(XP_DEFINE) CXXFLAGS=-Zi -TP -MP -W4 -EHsc -Zc:forScope -Zc:wchar_t $(CRTFLAGS) CXXDEBUG=-Od -MTd -DDEBUG CXXNDEBUG=-O1 -MT -DNDEBUG -GL |