Skip to content

Commit efab840

Browse files
committed
cppcheck-opensource#5230 Explicit reinterpret_cast should not give a warning. Lower all invalidPointerCast messages to 'portability'
1 parent 29b46cb commit efab840

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

lib/checkother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ void CheckOther::invalidPointerCast()
481481

482482
std::string fromType = analyzeType(fromTok);
483483
std::string toType = analyzeType(toTok);
484-
if (fromType != toType && !fromType.empty() && !toType.empty() && (toType != "integer" || _settings->isEnabled("portability")) && (toTok->str() != "char" || _settings->inconclusive))
484+
if (fromType != toType && !fromType.empty() && !toType.empty() && _settings->isEnabled("portability") && (toTok->str() != "char" || _settings->inconclusive))
485485
invalidPointerCastError(tok, fromType, toType, toTok->str() == "char");
486486
}
487487
}
@@ -495,7 +495,7 @@ void CheckOther::invalidPointerCastError(const Token* tok, const std::string& fr
495495
else
496496
reportError(tok, Severity::portability, "invalidPointerCast", "Casting from " + from + "* to char* is not portable due to different binary data representations on different platforms.", true);
497497
} else
498-
reportError(tok, Severity::warning, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation.");
498+
reportError(tok, Severity::portability, "invalidPointerCast", "Casting between " + from + "* and " + to + "* which have an incompatible binary data representation.");
499499
}
500500

501501
//---------------------------------------------------------------------------

test/testother.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ class TestOther : public TestFixture {
11981198
ASSERT_EQUALS("", errout.str());
11991199
}
12001200

1201-
void checkInvalidPointerCast(const char code[], bool portability = false, bool inconclusive = false) {
1201+
void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) {
12021202
// Clear the error buffer..
12031203
errout.str("");
12041204

@@ -1224,36 +1224,36 @@ class TestOther : public TestFixture {
12241224
" delete [] (double*)f;\n"
12251225
" delete [] (long double const*)(new float[10]);\n"
12261226
"}");
1227-
TODO_ASSERT_EQUALS("[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n"
1228-
"[test.cpp:4]: (warning) Casting between float* and long double* which have an incompatible binary data representation.\n",
1229-
"[test.cpp:3]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n"
1230-
"[test.cpp:4]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str());
1227+
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n"
1228+
"[test.cpp:4]: (portability) Casting between float* and long double* which have an incompatible binary data representation.\n",
1229+
"[test.cpp:3]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n"
1230+
"[test.cpp:4]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str());
12311231

12321232
checkInvalidPointerCast("void test(const float* f) {\n"
12331233
" double *d = (double*)f;\n"
12341234
"}");
1235-
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str());
1235+
ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between float* and double* which have an incompatible binary data representation.\n", errout.str());
12361236

12371237
checkInvalidPointerCast("void test(double* d1) {\n"
12381238
" long double *ld = (long double*)d1;\n"
12391239
" double *d2 = (double*)ld;\n"
12401240
"}");
1241-
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and long double* which have an incompatible binary data representation.\n"
1242-
"[test.cpp:3]: (warning) Casting between long double* and double* which have an incompatible binary data representation.\n", errout.str());
1241+
ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double* and long double* which have an incompatible binary data representation.\n"
1242+
"[test.cpp:3]: (portability) Casting between long double* and double* which have an incompatible binary data representation.\n", errout.str());
12431243

12441244
checkInvalidPointerCast("char* test(int* i) {\n"
12451245
" long double *d = (long double*)(i);\n"
12461246
" double *d = (double*)(i);\n"
12471247
" float *f = reinterpret_cast<float*>(i);\n"
12481248
"}");
1249-
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and long double* which have an incompatible binary data representation.\n"
1250-
"[test.cpp:3]: (warning) Casting between integer* and double* which have an incompatible binary data representation.\n"
1251-
"[test.cpp:4]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str());
1249+
ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between integer* and long double* which have an incompatible binary data representation.\n"
1250+
"[test.cpp:3]: (portability) Casting between integer* and double* which have an incompatible binary data representation.\n"
1251+
"[test.cpp:4]: (portability) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str());
12521252

12531253
checkInvalidPointerCast("float* test(unsigned int* i) {\n"
12541254
" return (float*)i;\n"
12551255
"}");
1256-
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str());
1256+
ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between integer* and float* which have an incompatible binary data representation.\n", errout.str());
12571257

12581258
checkInvalidPointerCast("float* test(unsigned int* i) {\n"
12591259
" return (float*)i[0];\n"
@@ -1263,7 +1263,7 @@ class TestOther : public TestFixture {
12631263
checkInvalidPointerCast("float* test(double& d) {\n"
12641264
" return (float*)&d;\n"
12651265
"}");
1266-
ASSERT_EQUALS("[test.cpp:2]: (warning) Casting between double* and float* which have an incompatible binary data representation.\n", errout.str());
1266+
ASSERT_EQUALS("[test.cpp:2]: (portability) Casting between double* and float* which have an incompatible binary data representation.\n", errout.str());
12671267

12681268
checkInvalidPointerCast("void test(float* data) {\n"
12691269
" f.write((char*)data,sizeof(float));\n"

0 commit comments

Comments
 (0)