Skip to content

Commit 06df4cf

Browse files
committed
Nits
1 parent e6a1609 commit 06df4cf

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/checkio.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFo
19381938

19391939
Severity CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo)
19401940
{
1941+
//TODO: It causes issues if we use fixed range types like int32_t etc so we should rewrite this to handle those types properly
19411942
return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning;
19421943
}
19431944

lib/symboldatabase.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8237,13 +8237,15 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett
82378237
else
82388238
type = ValueType::Type::UNKNOWN_INT;
82398239
sign = (podtype->sign == 'u') ? ValueType::UNSIGNED : ValueType::SIGNED;
8240-
originalTypeName = typestr;
8240+
if (originalTypeName.empty())
8241+
originalTypeName = typestr;
82418242
return true;
82428243
}
82438244
if (podtype && podtype->stdtype == Library::PodType::Type::NO) {
82448245
type = ValueType::Type::POD;
82458246
sign = ValueType::UNKNOWN_SIGN;
8246-
originalTypeName = typestr;
8247+
if (originalTypeName.empty())
8248+
originalTypeName = typestr;
82478249
return true;
82488250
}
82498251

@@ -8269,7 +8271,8 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett
82698271
pointer = 2;
82708272
if (platformType->mConstPtr)
82718273
constness = 1;
8272-
originalTypeName = typestr;
8274+
if (originalTypeName.empty())
8275+
originalTypeName = typestr;
82738276
return true;
82748277
}
82758278
if (!podtype && (typestr == "size_t" || typestr == "std::size_t")) {
@@ -8283,7 +8286,6 @@ bool ValueType::fromLibraryType(const std::string &typestr, const Settings &sett
82838286
type = ValueType::Type::INT;
82848287
else
82858288
type = ValueType::Type::UNKNOWN_INT;
8286-
originalTypeName = typestr;
82878289
return true;
82888290
}
82898291

test/testio.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,14 +2915,16 @@ class TestIO : public TestFixture {
29152915
"[test.cpp:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\n"
29162916
"[test.cpp:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", errout_str());
29172917

2918+
// We should revisit the logic behind portability checks here.
29182919
check("struct Fred { int32_t i; } f;\n"
29192920
"struct Fred & bar() { };\n"
2920-
"void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }");
2921-
ASSERT_EQUALS("[test.cpp:3]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'signed int'.\n"
2922-
"[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed int'.\n"
2923-
"[test.cpp:3]: (warning) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'signed int'.\n"
2924-
"[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'signed int'.\n"
2925-
"[test.cpp:3]: (warning) %Lf in format string (no. 6) requires 'long double' but the argument type is 'signed int'.\n",
2921+
"void foo() { printf(\"%d %ld %u %lu %f %Lf\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }",
2922+
dinit(CheckOptions, $.portability = true));
2923+
ASSERT_EQUALS("[test.cpp:3]: (portability) %ld in format string (no. 2) requires 'long' but the argument type is 'int32_t {aka signed int}'.\n"
2924+
"[test.cpp:3]: (portability) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'int32_t {aka signed int}'.\n"
2925+
"[test.cpp:3]: (portability) %lu in format string (no. 4) requires 'unsigned long' but the argument type is 'int32_t {aka signed int}'.\n"
2926+
"[test.cpp:3]: (portability) %f in format string (no. 5) requires 'double' but the argument type is 'int32_t {aka signed int}'.\n"
2927+
"[test.cpp:3]: (portability) %Lf in format string (no. 6) requires 'long double' but the argument type is 'int32_t {aka signed int}'.\n",
29262928
errout_str());
29272929

29282930
// #4984

0 commit comments

Comments
 (0)