Merge topic 'pvs-fixes'

e2f4b9bedc pvs-studio: (V522) Prevent possible null-pointer dereference in RemoveRPathELF
77b874baa8 pvs-studio: (V1086) Fix buffer writes
a77b7aa836 pvs-studio: (V557) Harden array boundary checks
7217af55da pvs-studio: (V555) Clarify size_type comparison

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !12077
This commit is contained in:
Brad King
2026-06-18 11:16:07 -04:00
committed by Kitware Robot
7 changed files with 21 additions and 18 deletions
+1 -7
View File
@@ -6,17 +6,13 @@
//-V::508
# The 'x' variable is assigned values twice successively. Perhaps this is a mistake.
//-V::519
# Possible null pointer dereference.
//-V::522
# Constant value is represented by an octal form.
//-V::536
# Iterators are passed as arguments to 'Foo' function. Consider inspecting the expression.
//-V::539
# Expression is always true/false.
//-V::547
# Expression of the 'A - B > 0' kind will work as 'A != B'.
//-V::555
# Possible array overrun.
# Array underrun/overrun is possible.
//-V::557
# Part of conditional expression is always true/false.
//-V::560
@@ -90,8 +86,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.
+8 -4
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);
+1 -1
View File
@@ -391,7 +391,7 @@ static bool DumpFileWithLlvmNm(std::string const& nmPath, char const* filename,
line.c_str());
return false;
}
if (line.size() < sym_end + 1) {
if (line.size() < sym_end) {
fprintf(stderr, "Couldn't parse llvm-nm output line: %s\n",
line.c_str());
return false;
+1 -1
View File
@@ -93,7 +93,7 @@ void cmStringReplaceHelper::ParseReplaceExpression()
this->Replacements.emplace_back(
this->ReplaceExpression.substr(l, r - l));
} else {
if (r - l > 0) {
if (r > l) {
this->Replacements.emplace_back(
this->ReplaceExpression.substr(l, r - l));
}
+2 -1
View File
@@ -3895,7 +3895,8 @@ static cm::optional<bool> RemoveRPathELF(std::string const& file,
// There is no RPATH or RUNPATH anyway.
return true;
}
if (se_count == 2 && se[1]->IndexInSection < se[0]->IndexInSection) {
if (se_count == 2 && se[0] && se[1] &&
se[1]->IndexInSection < se[0]->IndexInSection) {
std::swap(se[0], se[1]);
}
+6 -3
View File
@@ -81,14 +81,16 @@ bool cmTargetPropCommandBase::HandleArguments(
}
bool prepend = false;
if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE") {
if ((flags & PROCESS_BEFORE) && argIndex < args.size() &&
args[argIndex] == "BEFORE") {
if (args.size() < 3) {
this->SetError("called with incorrect number of arguments");
return false;
}
prepend = true;
++argIndex;
} else if ((flags & PROCESS_AFTER) && args[argIndex] == "AFTER") {
} else if ((flags & PROCESS_AFTER) && argIndex < args.size() &&
args[argIndex] == "AFTER") {
if (args.size() < 3) {
this->SetError("called with incorrect number of arguments");
return false;
@@ -97,7 +99,8 @@ bool cmTargetPropCommandBase::HandleArguments(
++argIndex;
}
if ((flags & PROCESS_REUSE_FROM) && args[argIndex] == "REUSE_FROM") {
if ((flags & PROCESS_REUSE_FROM) && argIndex < args.size() &&
args[argIndex] == "REUSE_FROM") {
if (args.size() != 3) {
this->SetError("called with incorrect number of arguments");
return false;
+2 -1
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;
}