Beruflich Dokumente
Kultur Dokumente
0 Test Report
Test Report
Stage of test Customer Name Drawing / Specification Number Vendor Name1
Final
30/08/2011 Cppcheck 2
HCLT
1 User-3
Manual
Calibration details
Visual C++
Parameters tested
Referenc e
Expected results
Actual results
OK / Not OK
TST-1.1
TST-1.2
User will be alerted with the following error message "[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter." User will be alerted with the following error message "[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter."
OK
No error found.
Not OK
void func1(int arr[2]) { int num=2; arr[0]=# } char *foo() { char str[100] = {0}; return str; }
TST-1.3 No error found. TST-1.4 user will be alerted with following error message "[test.cpp:4]: (error) Returning pointer to local array variable" No error found. TST-1.6 User will be alerted with the following error message "[test.cpp:3]: (error) Return of the address of an auto-variable." User will be alerted with the following error message "[test.cpp:4]: (error) Returning reference to auto variable" User will be alerted with the following error message "[test.cpp:4]: (error) Returning reference to auto variable" User will be alerted with the following error message "[test.cpp:4]: (error) Returning pointer to auto
(style) Variable 'num' is assigned a value that is never used (error) Returning pointer to local array variable
OK
OK
std::string foo() { char str[100] = {0}; return str; } int func1() { int num=2; return # }
TST-1.5
(style) Variable 'num' is assigned a value that is never used (style) Variable 'num' is assigned a value that is never used
OK
Not OK
TST-1.7
OK
TST-1.8
OK
TST-1.9
OK
HCLT Confidential
Page 2 of 21
x::~x() { throw e; }
TST-2.1
TST-2.2
TST-2.3
TST-3.1
TST-3.2
variable" User will be alerted with the following error message "[test.cpp:3]: (error) Throwing exception in destructor" User will be alerted with the following error message "[test.cpp:6]: (error) Throwing exception in invalid state, p points at deallocated memory" User will be alerted with the following error message "[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception." User will be alerted with the following error message "[test.cpp:4]: (error) Possible null pointer dereference: tok\n". User will be alerted with the following error message "[test.cpp:3]: (error) Possible null pointer
OK
OK
(style) Throwing a copy of the caught exception instead of rethrowing the original exception
OK
OK
(error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 0
Not OK
HCLT Confidential
Page 3 of 21
dereference: abc - otherwise it is redundant to check if abc is null at line 4\n". int *test(int *Z) { int *Q=NULL; if (Z) { Q = Z; } else { try { } catch(...){ } } *Q=1; return Q; } void foo(struct ABC *abc) { if (abc && abc->a); if (!abc); } void f() { int *p = new(std::nothrow) int; } TST-3.3 User will be alerted with the following error message "[test.cpp:12]: (error) Possible null pointer dereference: Q\n". TST-3.4 No error found. TST-4.1 User will be alerted with the following error message "[test.cpp:4]: (error) Memory leak: p\n". User will be alerted with the following error message "[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n". User will be alerted with the following error message "[test.cpp:4]: (error) Memory leak: p\n". User will be alerted with the following error
HCLT Confidential
No error found.
Not OK
No error found
OK
OK
TST-4.2
OK
TST-4.3
OK
TST-4.4
(error) Common realloc mistake: 'buf' nulled but not freed upon
Not OK
Page 4 of 21
message "[test.cpp:6]: (error) Common realloc mistake: \'buf\' nulled but not freed upon failure\n". TST-4.5 Registration page should have all the required fields. TST-4.6 User will be alerted with the following error message "[test.cpp:9]: (error) Memory leak: str\n".
Failure. (error) Mismatching allocation and deallocation: buf (error) Mismatching allocation and deallocation: x (error) Mismatching allocation and deallocation: str (error) Memory leak: str Not OK
void foo() { int *x = new int[10]; if (x == 0 || aa) { return 1; } delete [] x; void f() { char *str = new char[10]; while (abc) { switch (def) { default: return; } } delete [] str; } static char * f() { char *c = new char[50]; return (c ? c : NULL); } void foo() char *str = malloc(10); free(str); strcpy(str, p); }
Not OK
TST-4.7 No Error message. { TST-4.8 User will be alerted with the following error message "[test.cpp:4]: (error) Dereferencing 'str' after it is deallocated / released\n". { TST-4.9 No Error message.
(style) Variable 'c' is assigned a value that is never used (error) Mismatching allocation and deallocation: str (error) Dereferencing 'str' after it is deallocated / r (error) Uninitialized variable: str (style) Variable 'str' is allocated memory that is never used
OK
Not OK
Not OK
HCLT Confidential
Page 5 of 21
TST-4.10
User will be alerted with the following error message "[test.cpp:5]: (error) Deallocating a deallocated pointer: str. No Error message.
(error) Mismatching allocation and deallocation: str (error) Mismatching allocation and deallocation: str (error) Deallocating a deallocated pointer: str (error) Resource leak: fd
Not OK
void foo() { FILE *fd = fopen(\test.txt\, \wb\); fprintf(fd, \test\); fclose(fd); } void f(std::string foo) { char *out = new char[11]; memset(&(out[0]), 0, 1); } void f() { FILE *f = tmpfile(); }
TST-4.11
Not OK
TST-4.12
TST-4.13
TST-4.14
TST-4.15
User will be alerted with the following error message "[test.cpp:5]: (error) Memory leak: out\n" User will be alerted with the following error message "[test.cpp:4]: (error) Resource leak: f\n" User will be alerted with the following error message "[test.cpp:3]: (error) The given size is mismatching\n" User will be alerted with the following error message "[test.cpp:2]: (error) Allocation with strdup, strcpy doesn't
OK
OK
(error) The given size 3 is mismatching (error) Mismatching allocation and deallocation: p (error) Allocation with strdup, strcpy doesn't release it.
Not OK
OK
HCLT Confidential
Page 6 of 21
release it.\n" #include <iostream> class K { }; int main(int argc, char *argv[ ]) { K k(1); std::cout << k << std::endl; if(k) { k++; } std::cout << k << std::endl; return 0; } #include <iostream> class K {}; int main(int argc, char *argv[]) { K k(0); std::cout << k << std::endl; ++k; std::cout << k << std::endl; return 0; } #include <iostream> #include <vector> int main() { std::vector<int> v; std::vector<int>::iterator it; for( int i=0; i < 10; ++i ) v.push_back(i); unsigned int total = 0; std::vector<int>::reverse_iterator rit; rit= v.rend(); while( rit != v.rbegin() ) { rit--; } return 0; } void f( ) { char *s = malloc(100); *s += 10; } User will be alerted with the following performance message "[test.cpp:7]: (performance) Prefer prefix + +/-- operators for non-primitive types.\n". (performance) Prefer prefix + +/-- operators for nonprimitive types. OK
TST-5.1
TST-5.2
No Error found.
TST-5.3
User will be alerted with the following error message "[test.cpp:7]: (performance) Prefer prefix + +/-- operators for non-primitive types.\n".
(performance) Prefer prefix + +/-- operators for nonprimitive types. (information) Include file: "vector" not found. (information) Include file: "iostream" not found. (error) Data is allocated but not initialized: s (error) Memory leak: s (style) Variable
OK
TST-6.1
void f()
TST-6.2
User will be alerted with the following error message ""[test.cpp:4]: (error) Data is allocated but not initialized: s\n". User will be
Not OK
OK
HCLT Confidential
Page 7 of 21
static void foo(int x) { int a; if (x==1); if (x==2); x = a; } int foo() { int i; if (x) i = 22; else { char *y = {0}; i = 33; } return i; } void foo() { std::vector<int> ints1; std::vector<int> ints2; std::vector<int>::iterator it = std::find(ints1.begin(), ints2.end(), 22); } void foo(const std::set<int> &ints1) { std::set<int> ints2; std::set<int>::iterator it1 = ints1.begin(); std::set<int>::iterator it2 = ints1.end(); ints2.insert(it1, it2);} void foo() { list<int> l1; list<int> l2; list<int>::iterator it = l1.begin(); while (it != l2.end()) { ++it; } }
TST-6.3
alerted with the following error message "[test.cpp:5]: (error) Uninitialized variable: a\n". User will be alerted with the following error message "[test.cpp:6]: (error) Uninitialized variable: a\n".
'a' is assigned a value that is never used (error) Uninitialized variable: a OK (error) Uninitialized variable: a
No Error message.
OK
TST-6.4
No Error message.
TST-7.1
User will be alerted with the following error message "[test.cpp:5]: (error) mismatching containers\n". No Error message. User will be alerted with the following error message "[test.cpp:6]: (error) Same iterator is used with both l1 and
OK
OK
TST-7.3
OK
HCLT Confidential
Page 8 of 21
l2\n". void foo(std::vector<std::string> &test) { std::set<int> result; for(std::vector<std::string>::const_iterator cit = test.begin();cit != test.end() ++cit) { result.insert(cit->size()); } } void f() { std::vector<int> ints; std::vector<int>::iterator iter; iter = ints.begin() + 2; ints.erase(iter); std::cout << (*iter) << std::endl; } for (it = foo.begin(); it != foo.end(); ++it) { foo.erase(it); } for (it = foo.begin(); it != foo.end(); ++it) { foo.erase(it); } static void f() { for (iterator it = foo.begin(); it != foo.end(); it = next) { next = it; next++; foo.erase(it); } } void f(std::vector<ints> &ints) { std::vector<int>::iterator iter; iter = ints.begin() + 2; ints.erase(iter); ints.erase(iter); } void f(const std::vector<int> &foo) No Error message No Error message OK
TST-7.4
TST-7.5
TST-7.6
User will be alerted with the following error message "[test.cpp:7]: (error) Dereferenced iterator 'iter' has been erased\n". User will be alerted with the following error message "[test.cpp:3]: (error) Dangerous iterator usage after erase()method.\n".
OK
OK
OK
TST-7.7
TST-7.8
TST-7.9
User will be alerted with the following error message "[test.cpp:6]: (error) Invalid iterator: iter\n". User will be
OK
(error) After
OK
HCLT Confidential
Page 9 of 21
{ std::vector<int>::const_iterator it = foo.begin();foo.push_back(123);*it; }
alerted with the following error message "[test.cpp:5]: (error) After push_back, the iterator 'it' may be invalid\n".
void f() { std::vector<int>::const_iterator it = foo.begin(); foo.push_back(123); { int *it = &foo[0]; *it = 456; } } void f() { if (haystack.find(needle) != haystack.end()) { haystack.remove(needle); } } void f() std::string errmsg; throw errmsg.c_str(); } {
OK
TST-7.11
User will be alerted with the following style message "[test.cpp:3]: (style) Redundant checking of STL container element.\n". User will be alerted with the following error message "[test.cpp:3]: (error) Dangerous usage of c_str()\n" User will be alerted with the following warning message "[test.cpp:4]: (warning) Missing bounds check for extra iterator increment in loop.\n", errout.str()); No Error message.
OK
OK
TST-7.12
void f(std::set<int> &ints) { for (std::set<int>::iterator it = ints.begin(); it != ints.end(); ++it) { if (a) { it++; } } } TST-7.13
TST-7.14
(warning) Missing bounds check for extra iterator increment in loop. (Performance) Prefer prefix + +/-- operators for non primitive types. No Error message.
Not OK
OK
HCLT Confidential
Page 10 of 21
{ ++it->second; } } void f() { if (std::find(a,b,c)) { } } TST-7.15 User will be alerted with the following warning message "[test.cpp:3]: (warning) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n". No Error message. User will be alerted with the following error message "[test.cpp:5]: (error) Division by zero\n" User will be alerted with the following performance message "[test.cpp:3]: (error) Division by zero. User will be alerted with the following error message "[test.cpp:3]: (error) Passing value -2 to log() leads to undefined result\n" User will be alerted with the following error message "[test.cpp:3]: (warning) Suspicious condition. The result of find is an iterator, but it is not properly checked. OK
TST-7.16
OK
OK
TST-8.1
OK
TST-8.2
OK
TST-8.3
TST-8.4
OK
HCLT Confidential
Page 11 of 21
(error) Passing value 0 to log() leads to undefined result\n" void foo() { std::string *log(0); } void foo() { unsigned int r=32; int v=r/-2; } TST-8.5 No error message User will be alerted with the following error message "[test.cpp:4]: (error) Unsigned Division. The result will be wrong. User will be alerted with the following error message "[test.cpp:3]: (error) Invalid radix in call to strtol or strtoul. Must be 0 or 236\n" No error message. User will be alerted with the following error message "[test.cpp:2]: (error) Using sizeof for array given as function argument returns the size of pointer.\n" User will be alerted with the following error message "[test.cpp:2]: (error) Using No error message No error message OK
Not OK
TST-8.6
TST-8.7
OK
TST-8.8
No error message. (error) Using sizeof for array given as function argument returns the size of pointer.
OK
OK
TST-8.9
void f( int a[], int b) { std::cout << sizeof(a) / sizeof(int) << std::endl; }
TST-8.10
(error) Using sizeof for array given as function argument returns the size
OK
HCLT Confidential
Page 12 of 21
TST-8.11
TST-8.12
TST-8.13
TST-8.14
sizeof for array given as function argument returns the size of pointer.\n" User will be alerted with the following performance message "[test.cpp:2]: (performance) Function parameter 'foo' should be passed by reference.\n" User will be alerted with the following performance message "[test.cpp:1]: (performance) Function parameter 'v' should be passed by reference.\n" No error message. User will be alerted with the following error message "[test.cpp:3]: (error) fflush() called on input stream \"stdin\" may result in undefined behaviour\n" No error message. User will be alerted with the following error message "[test.cpp:4]:
of pointer.
OK
No error message. (error) fflush() called on input stream "stdin" may result in undefined behaviour
OK OK
void foo( ) { fflush(stdout); } class NotAFunction ; int function ( ) { NotAFunction ( 123 ); return 0 ;
TST-8.15 TST-8.16
OK
OK
HCLT Confidential
Page 13 of 21
(error) instance of \"NotAFunctio n\" object destroyed immediately\n" TST-8.17 No error message. No error message. OK
TST-8.18
User will be alerted with the following style message "[test.cpp:4]: (style) C-style pointer casting\n". User will be alerted with the following style message "[test.cpp:6]: (style) Exception should be caught by reference.\n"
No error message.
Not OK
TST-8.19
OK
{ TST-8.20
User will be alerted with the following error message "[test.cpp:6]: (style) Exception should be caught by reference.\n"
(style) Exception should be caught by reference. (style) Throwing a copy of the caught exception instead of rethrowing the original exception No error message.
Not OK
OK
HCLT Confidential
Page 14 of 21
TST-8.22
TST-8.23
User will be alerted with the following information message "[test.cpp:2]: (information) Please clarify precedence: 'a*b?..'\n" User will be alerted with the following warning message "[test.cpp:4]: (warning)Assert statement modifies 'a'. User will be alerted with the following warning message "[test.cpp:4]: (warning)Assert statement modifies 'b'. User will be alerted with the following warning message "[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n" User will be alerted with the following warning message "[test.cpp:1]: (warning) Found calculation inside sizeof()\n" User will be alerted with the following
OK
(warning) Assert statement modifies 'a'. (style) Variable 'a' is assigned a value that is never used (style) Variable 'a' is assigned a value that is never used (style) Variable 'b' is assigned a value that is never used (warning) Assert statement modifies 'b'. (warning) Calling sizeof for 'sizeof'.
Not OK
Not OK
TST-8.24
OK
TST-8.25
sizeof(a+b)
TST-8.26
OK
TST-8.27
Not OK
HCLT Confidential
Page 15 of 21
warning message "[test.cpp:7]: (warning) Redundant assignment of \"y\" in switch\n" User will be alerted with the following warning message "[test.cpp:4]: (warning) Redundant assignment of \"x\" to itself\n" No error message User will be alerted with the following warning message "[test.cpp:2]: (warning) Mutual exclusion over || always evaluates to true." User will be alerted with the following style message "[test.cpp:4]: (style) 'operator=' should return reference to self\n", errout.str()); No Error message.
never used (information) The scope of the variable y can be reduced (warning) Redundant assignment of "y" in switch (style) Variable 'x' is assigned a value that is never used
Not OK
TST-8.28
OK
TST-8.30
(warning) Mutual exclusion over || always evaluates to true. Did you intend to use && instead? (style) 'operator=' should return reference to self
OK
OK
class A { public: A & operator=(const A &a) { return a; } }; class A { public: A & operator=(const A &);
TST-9.1
TST-9.2
No Error message.
OK
HCLT Confidential
Page 16 of 21
}; A & A::operator=(const A &a) { return *this; } class A { public: char *s; A & operator=(const A &a) { free(s); s = strdup(a.s); return *this; } }; class A { public: A & operator=(const A &); }; A & A::operator=(const A &a) { if (&a ! = this) { } return *this; } enum ECODES { CODE_1 = 0, CODE_2 = 1 }; class Fred { public: Fred() {} private: ECODES _code; }; class C { FILE *fp; public: C(FILE *fp); }; C::C(FILE *fp) { C::fp = fp; } class Fred { int i; };
TST-9.3
User will be alerted with the following warning message "[test.cpp:5]: (warning) 'operator=' should check for assignment to self\n". No Error message. User will be alerted with the following warning message ""[test.cpp:10]: (warning) Member variable 'Fred::_code' is not initialised in the constructor.\n".
OK
No Error message.
OK
TST-9.4
TST-9.5
OK
OK
TST-9.7
User will be alerted with the following style message "[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n",
OK
HCLT Confidential
Page 17 of 21
errout.str()); class Fred { public: static void foobar(); }; void Fred::foobar() {} struct A { void g( struct sockaddr_in6& a); private: std::string b; }; void f() { struct A fail; memset(&fail, 0, sizeof(struct A)); } No Error message. TST-9.8 No Error message. OK
TST-9.9
User will be alerted with the following error message "[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'\n". User will be alerted with the following warning message "[test.cpp:2]: (warning) Suspicious pointer subtraction. User will be alerted with the following information message "[test.cpp:3]: (information) Technically the member function 'Fred::foo' can be const.\n". User will be alerted with the following style message "[test.cpp:3]: (style) Found obsolete function 'bsd_signal'. It is recommended
OK
OK
TST-9.10
{ TST-9.11 };
OK
TST-10.1
(style) Found obsolete function 'bsd_signal'. It is recommended that new applications use the 'sigaction' function
OK
HCLT Confidential
Page 18 of 21
that new applications use the 'sigaction' function\n". int f() { int bsd_signal(0); return bsd_signal; } TST-10.2 No Style message. User will be alerted with the following style message ""[test.cpp:4]: (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getnameinfo' function\n". User will be alerted with the following style message "[test.cpp:5]: (style) Found obsolete function 'gethostbyaddr'. It is recommended that new applications use the 'getaddrinfo' function\n" User will be alerted with the following style message "[test.cpp:3]: (style) Found obsolete function 'usleep'. It is recommended that new (style) Variable 'bsd_signal' is assigned a value that is never used (style) Variable 'hp' is assigned a value that is never used (style) Found obsolete function 'gethostbyname'. It is recommended that new applications use the 'getnameinfo' function (style) Variable 'addr' is assigned a value that is never used (style) Found obsolete function 'gethostbyaddr'. It is recommended that new appications use the 'getaddrinfo' function (style) Found obsolete function 'usleep'. It is recommended that new applications use the 'nanosleep' or 'setitimer' function. Not OK
Not OK
TST-10.3
Not OK
void f() { long addr; addr = inet_addr('127.0.0.1'); if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) { exit(1); } }
TST-10.4
TST-10.5
OK
HCLT Confidential
Page 19 of 21
TST-10.6
applications use the 'nanosleep' or 'setitimer' function\n". User will be alerted with the following style message "[test.cpp:4]: (style) Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead\n". No Style message User will be alerted with the following style message "[test.cpp:3]: (style) Found obsolete function 'gets'. It is recommended to use the function 'fgets' instead\n". User will be alerted with the following error message "[test.cpp:4]: (error) Array 'data[2]' index 4 out of bounds\n" User will be alerted with the following error message "[test.cpp:5]: (error) Array 'str[16]' index 16 out of bounds\n" User will be alerted with the
(style) Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead
OK
TST-10.7
No Style message (style) Found obsolete function 'gets'. It is recommended to use the function fgets' instead
OK
OK
TST-10.8
OK
TST-11.1
No Error message
Not OK
TST-11.2
TST-11.3
Not OK
HCLT Confidential
Page 20 of 21
int val[50]; int i, sum=0; for (i = 0; i < 100; i++) sum += val[i]; }
following style message "[test.cpp:6]: (error) Buffer access out-ofbounds: val\n" User will be alerted with the following style message "[test.cpp:4]: (error) Buffer overrun possible for long cmd-line args\n"
a value that is never used (error) Buffer access out-ofbounds: val (error) Uninitialized variable: val (error) Buffer overrun possible for long cmdline args
OK
TST-11.4
Re-inspection by
Re-inspection date
Remarks
Test Result:
Accepted
Rejected
HCLT Confidential
Page 21 of 21