updated error message about assigning address to integer. Thanks Kimmo for the suggestion.

This commit is contained in:
Daniel Marjamäki 2011-07-06 12:57:45 +02:00
parent 8f0f184058
commit 827fb01ec1
2 changed files with 10 additions and 6 deletions

View File

@ -63,6 +63,10 @@ void Check64BitPortability::pointerassignment()
void Check64BitPortability::pointerassignmentError(const Token *tok)
{
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).");
}

View File

@ -76,21 +76,21 @@ private:
" int a = p;\n"
" return a + 4;\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"
"{\n"
" int a = p;\n"
" return a + 4;\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"
"{\n"
" int *p = x;\n"
" *p = 0;\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()
@ -99,7 +99,7 @@ private:
"void f(struct Foo *foo) {\n"
" int i = foo->p;\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());
}
};