pvs-studio: (V1086) Fix buffer writes

Replace space-filling memset calls with bounded character initialization that
preserves null termination for the curses help text buffers.
This commit is contained in:
Martin Duffy
2026-05-18 01:47:54 -04:00
parent a77b7aa836
commit 77b874baa8
3 changed files with 10 additions and 7 deletions

View File

@@ -88,8 +88,6 @@
//-V::1071
# Conditional initialization inside the constructor may leave some members uninitialized.
//-V::1077
# Call of the 'Foo' function will lead to buffer underflow.
//-V::1086
# Waiting on condition variable without predicate. A thread can wait indefinitely or experience a spurious wake-up.
//-V::1089
# The 'emplace' / 'insert' function call contains potentially dangerous move operation. Moved object can be destroyed even if there is no insertion.

View File

@@ -314,9 +314,12 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
char secondLine[512] = "";
char thirdLine[512] = "";
if (process) {
memset(firstLine, ' ', 68);
memset(secondLine, ' ', 68);
memset(thirdLine, ' ', 68);
std::fill_n(firstLine, 68, ' ');
firstLine[68] = '\0';
std::fill_n(secondLine, 68, ' ');
secondLine[68] = '\0';
std::fill_n(thirdLine, 68, ' ');
thirdLine[68] = '\0';
} else {
if (this->OkToGenerate) {
snprintf(firstLine, sizeof(firstLine),
@@ -340,7 +343,8 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */)
move(y - 4, 0);
char fmt[512] = "Keys: [enter] Edit an entry [d] Delete an entry";
if (process) {
memset(fmt, ' ', 57);
std::fill_n(fmt, 57, ' ');
fmt[57] = '\0';
}
printw(fmt_s, fmt);
move(y - 3, 0);

View File

@@ -246,7 +246,8 @@ static bool testUVStreambufRead(
<< std::endl;
goto end;
}
if (std::memcmp(inputData.data(), outputData, 64)) {
if (std::memcmp(inputData.data(), outputData, //-V1086 Ignore underflow
64)) {
std::cout << "Read data does not match write data" << std::endl;
goto end;
}