* Fix #11708 "internal error: converting '1f' to integer failed - not an integer" with width in printf format string * Format
This commit is contained in:
parent
518b6a27ab
commit
e6576dd949
|
@ -150,7 +150,8 @@ static int getMinFormatStringOutputLength(const std::vector<const Token*> ¶m
|
||||||
|
|
||||||
if (digits_string.find('.') != std::string::npos) {
|
if (digits_string.find('.') != std::string::npos) {
|
||||||
const std::string endStr = digits_string.substr(digits_string.find('.') + 1);
|
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') {
|
if (formatString[i] == 's') {
|
||||||
// For strings, the length after the dot "%.2s" will limit
|
// For strings, the length after the dot "%.2s" will limit
|
||||||
|
|
|
@ -234,6 +234,7 @@ private:
|
||||||
TEST_CASE(buffer_overrun_33); //#2019
|
TEST_CASE(buffer_overrun_33); //#2019
|
||||||
TEST_CASE(buffer_overrun_34); //#11035
|
TEST_CASE(buffer_overrun_34); //#11035
|
||||||
TEST_CASE(buffer_overrun_35); //#2304
|
TEST_CASE(buffer_overrun_35); //#2304
|
||||||
|
TEST_CASE(buffer_overrun_36);
|
||||||
TEST_CASE(buffer_overrun_errorpath);
|
TEST_CASE(buffer_overrun_errorpath);
|
||||||
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
|
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
|
||||||
TEST_CASE(buffer_overrun_function_array_argument);
|
TEST_CASE(buffer_overrun_function_array_argument);
|
||||||
|
@ -3342,6 +3343,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void buffer_overrun_errorpath() {
|
||||||
setMultiline();
|
setMultiline();
|
||||||
const Settings settingsOld = settings0;
|
const Settings settingsOld = settings0;
|
||||||
|
|
Loading…
Reference in New Issue