Check for str being a null pointer before parsing string as an int32

This commit is contained in:
Tobias Markus 2024-05-14 08:15:09 +02:00
parent 33af80a883
commit 88f6706e99

View File

@ -1322,6 +1322,15 @@ static std::string FlagToEnvVar(const char* flag) {
// the result to *value and returns true; otherwise leaves *value // the result to *value and returns true; otherwise leaves *value
// unchanged and returns false. // unchanged and returns false.
bool ParseInt32(const Message& src_text, const char* str, int32_t* value) { bool ParseInt32(const Message& src_text, const char* str, int32_t* value) {
if (str == nullptr) {
Message msg;
msg << "WARNING: " << src_text
<< " is NULL and can not be parsed for a 32-bit signed integer";
printf("%s", msg.GetString().c_str());
fflush(stdout);
return false;
}
// Parses the environment variable as a decimal integer. // Parses the environment variable as a decimal integer.
char* end = nullptr; char* end = nullptr;
const long long_value = strtol(str, &end, 10); // NOLINT const long long_value = strtol(str, &end, 10); // NOLINT