updated error message about assigning address to integer. Thanks Kimmo for the suggestion.
This commit is contained in:
parent
8f0f184058
commit
827fb01ec1
|
@ -63,6 +63,10 @@ void Check64BitPortability::pointerassignment()
|
||||||
void Check64BitPortability::pointerassignmentError(const Token *tok)
|
void Check64BitPortability::pointerassignmentError(const Token *tok)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::portability,
|
reportError(tok, Severity::portability,
|
||||||
"addresstoint", "Assigning address to int/long is not portable"
|
"addresstoint",
|
||||||
);
|
"Assigning an address value to the integer (int/long/etc) type is not portable\n"
|
||||||
|
"Assigning an address value to the integer (int/long/etc) type is not portable across different platforms and "
|
||||||
|
"compilers. For example in 32-bit Windows and linux they are same width, but in 64-bit Windows and linux "
|
||||||
|
"they are of different width. In worst case you end up assigning 64-bit address to 32-bit integer. The safe "
|
||||||
|
"way is to always assign addresses only to pointer types (or typedefs).");
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,21 +76,21 @@ private:
|
||||||
" int a = p;\n"
|
" int a = p;\n"
|
||||||
" return a + 4;\n"
|
" return a + 4;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning address to int/long is not portable\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an address value to the integer (int/long/etc) type is not portable\n", errout.str());
|
||||||
|
|
||||||
check("int foo(int p[])\n"
|
check("int foo(int p[])\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int a = p;\n"
|
" int a = p;\n"
|
||||||
" return a + 4;\n"
|
" return a + 4;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning address to int/long is not portable\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an address value to the integer (int/long/etc) type is not portable\n", "", errout.str());
|
||||||
|
|
||||||
check("void foo(int x)\n"
|
check("void foo(int x)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" int *p = x;\n"
|
" int *p = x;\n"
|
||||||
" *p = 0;\n"
|
" *p = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning int/long to pointer is not portable\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an address value to the integer (int/long/etc) type is not portable\n", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void structmember()
|
void structmember()
|
||||||
|
@ -99,7 +99,7 @@ private:
|
||||||
"void f(struct Foo *foo) {\n"
|
"void f(struct Foo *foo) {\n"
|
||||||
" int i = foo->p;\n"
|
" int i = foo->p;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning address to int/long is not portable\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an address value to the integer (int/long/etc) type is not portable\n", "", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue