Skip to content

Commit 7ae7cdd

Browse files
committed
test/cfg: Added test cases for std::string find, that demonstrate false negatives in case of uninitialized variable (danmar#6991).
1 parent 5e50166 commit 7ae7cdd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/cfg/std.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,21 @@ void uninitvar_setbase(void)
27092709
std::cout << std::setbase(p);
27102710
}
27112711

2712+
void uninivar_find(std::string s)
2713+
{
2714+
// testing of size_t find (const string& str, size_t pos = 0)
2715+
size_t pos;
2716+
// cppcheck-suppress uninitvar
2717+
(void)s.find("find",pos); // #6991
2718+
2719+
// testing of size_t find (const char* s, size_t pos = 0) const;
2720+
char *c;
2721+
// cppcheck-suppress uninitvar
2722+
(void)s.find(c,0);
2723+
// cppcheck-suppress uninitvar
2724+
(void)s.find(c,pos);
2725+
}
2726+
27122727
void invalidFunctionArgBool_abs(bool b, double x, double y)
27132728
{
27142729
// cppcheck-suppress invalidFunctionArgBool

0 commit comments

Comments
 (0)