diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 7b1a040ae..ee8f1506d 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -150,7 +150,8 @@ static int getMinFormatStringOutputLength(const std::vector ¶m 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(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 diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index d45d8f27e..4c2560ecc 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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;