Fix #11708 internal error: converting '1f' to integer failed (#5066)

* Fix #11708 "internal error: converting '1f' to integer failed - not an integer" with width in printf format string

* Format
This commit is contained in:
chrchr-github 2023-05-18 23:26:56 +02:00 committed by GitHub
parent 518b6a27ab
commit e6576dd949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -150,7 +150,8 @@ static int getMinFormatStringOutputLength(const std::vector<const Token*> &param
if (digits_string.find('.') != std::string::npos) {
const std::string endStr = digits_string.substr(digits_string.find('.') + 1);
const int maxLen = std::max(std::abs(strToInt<int>(endStr)), 1);
// NOLINTNEXTLINE(cert-err34-c) - intentional use
const int maxLen = std::max(std::abs(std::atoi(endStr.c_str())), 1);
if (formatString[i] == 's') {
// For strings, the length after the dot "%.2s" will limit

View File

@ -234,6 +234,7 @@ private:
TEST_CASE(buffer_overrun_33); //#2019
TEST_CASE(buffer_overrun_34); //#11035
TEST_CASE(buffer_overrun_35); //#2304
TEST_CASE(buffer_overrun_36);
TEST_CASE(buffer_overrun_errorpath);
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
TEST_CASE(buffer_overrun_function_array_argument);
@ -3342,6 +3343,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_36() { // #11708
check("void f(double d) {\n"
" char a[80];\n"
" sprintf(a, \"%2.1f\", d);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_errorpath() {
setMultiline();
const Settings settingsOld = settings0;