More tests for checking negative pointers

This commit is contained in:
Dmitry-Me 2015-03-19 16:46:00 +03:00
parent 302d4d4e71
commit 818346622c
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])"