Merge pull request #560 from Dmitry-Me/moreNegativePointerTests

More tests for checking negative pointers
This commit is contained in:
Daniel Marjamäki 2015-03-20 06:30:03 +01:00
commit 42b310e337
1 changed files with 81 additions and 0 deletions

View File

@ -4677,6 +4677,87 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first) {\n"
" if (first.ptr >= 0) {} \n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if((first.ptr - second.ptr) >= 0) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first) {\n"
" if((first.ptr) >= 0) {} \n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not.\n", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if(0 <= first.ptr - second.ptr) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if(0 <= (first.ptr - second.ptr)) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if(first.ptr - second.ptr < 0) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if((first.ptr - second.ptr) < 0) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if(0 > first.ptr - second.ptr) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"struct S {\n"
" int* ptr;\n"
"};\n"
"void foo(S* first, S* second) {\n"
" if(0 > (first.ptr - second.ptr)) {} \n"
"}");
ASSERT_EQUALS("", errout.str());
check_signOfUnsignedVariable(
"bool foo(int* x) {\n"
" if (0 <= x[0])"