Fix read of 64bit enviroment variables

change atoi to atoll

Signed-off-by: Cencelewska, Katarzyna <katarzyna.cencelewska@intel.com>
This commit is contained in:
Cencelewska, Katarzyna
2022-09-09 13:19:21 +00:00
committed by Compute-Runtime-Automation
parent 69c9a4e86c
commit 9b19014cf1
5 changed files with 28 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -29,7 +29,7 @@ int64_t EnvironmentVariableReader::getSetting(const char *settingName, int64_t d
envValue = IoFunctions::getenvPtr(settingName);
if (envValue) {
value = atoi(envValue);
value = atoll(envValue);
}
return value;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -82,7 +82,7 @@ int64_t RegistryReader::getSetting(const char *settingName, int64_t defaultValue
if (readSettingFromEnv) {
const char *envValue = getenv(settingName);
if (envValue) {
value = atoi(envValue);
value = atoll(envValue);
}
}

View File

@@ -65,6 +65,20 @@ TEST_F(DebugEnvReaderTests, GivenSetVariableThenSetValueIsReturned) {
}
}
TEST_F(DebugEnvReaderTests, givenMaxInt64AsEnvWhenGetSettingThenProperValueIsReturned) {
const char *testingVariableName = "TestingVariable";
const char *testingVariableValue = "9223372036854775807";
int64_t expectedValue = 9223372036854775807;
int64_t defaultValue = 0;
VariableBackup<uint32_t> mockGetenvCalledBackup(&IoFunctions::mockGetenvCalled, 0);
std::unordered_map<std::string, std::string> mockableEnvs = {{testingVariableName, testingVariableValue}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
EXPECT_EQ(expectedValue, evr->getSetting(testingVariableName, defaultValue));
EXPECT_EQ(1u, IoFunctions::mockGetenvCalled);
}
TEST_F(DebugEnvReaderTests, GivenUnsetVariableThenDefaultValueIsReturned) {
int32_t ret;
std::string retString;