From 827fb01ec19c9ab2be07840c14f93f915866eb3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 6 Jul 2011 12:57:45 +0200 Subject: [PATCH] updated error message about assigning address to integer. Thanks Kimmo for the suggestion. --- lib/check64bit.cpp | 8 ++++++-- test/test64bit.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/check64bit.cpp b/lib/check64bit.cpp index 9dc0c41ea..cda31dd30 100644 --- a/lib/check64bit.cpp +++ b/lib/check64bit.cpp @@ -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)."); } diff --git a/test/test64bit.cpp b/test/test64bit.cpp index fe1f8e1cb..57e22b3d9 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -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()); } };