Fix GCC 12 -Wrestrict warning in util.cpp (argv_to_string/join)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
11
mac/util.cpp
11
mac/util.cpp
@@ -229,7 +229,10 @@ std::string join(int argc, char* argv[], const std::string& separator)
|
|||||||
{
|
{
|
||||||
std::string result {};
|
std::string result {};
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
result += std::string(argv[i]) + separator;
|
// Append directly (see argv_to_string): avoids a temporary and the same
|
||||||
|
// GCC 12 -Wrestrict false positive.
|
||||||
|
result += argv[i];
|
||||||
|
result += separator;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -241,7 +244,11 @@ std::string argv_to_string(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
std::string result = argv[0];
|
std::string result = argv[0];
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
result += " " + std::string(argv[i]);
|
// Append the pieces directly rather than building a `" " + string(...)`
|
||||||
|
// temporary: identical result, avoids an allocation, and sidesteps a
|
||||||
|
// GCC 12 -Wrestrict false positive on the temporary's memcpy.
|
||||||
|
result += ' ';
|
||||||
|
result += argv[i];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user