Source: Avoid gcc 12 compilation warning

GCC 12 warns:

    warning: '%04d' directive output may be truncated writing between
    4 and 11 bytes into a region of size 5 [-Wformat-truncation=]

The surrounding logic guarantees the formatted integer will never
be more than 4 bytes, but it doesn't hurt to use a larger buffer.
This GCC behavior is documented:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104012#c5
This commit is contained in:
Brad King
2022-01-28 07:57:35 -05:00
parent ee1bed5058
commit ae101921e8

View File

@@ -1274,7 +1274,7 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable(
cmSystemTools::ReplaceString(ret, "-", "__");
cmSystemTools::ReplaceString(ret, "+", "___");
int ni = 0;
char buffer[5];
char buffer[12];
// make sure the _ version is not already used, if
// it is used then add number to the end of the variable
while (this->ShortMakeVariableMap.count(ret) && ni < 1000) {
@@ -1302,7 +1302,7 @@ std::string cmLocalUnixMakefileGenerator3::CreateMakeVariable(
if (static_cast<int>(str1.size()) + static_cast<int>(str2.size()) > size) {
str1 = str1.substr(0, size - str2.size());
}
char buffer[5];
char buffer[12];
int ni = 0;
snprintf(buffer, sizeof(buffer), "%04d", ni);
ret = str1 + str2 + buffer;