Skip to content

Commit cdc8801

Browse files
author
Daniel Marjamäki
committed
Fixed cppcheck-opensource#2334 (Internal class index function (no need to 'strchr'))
1 parent c0bedb5 commit cdc8801

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎lib/checkobsoletefunctions.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class CheckObsoleteFunctions : public Check
9090

9191
_obsoleteFunctions.push_back(std::make_pair("getwd","Found obsolete function 'getwd'. It is recommended that new applications use the 'getcwd' function"));
9292

93+
/* Disabled to fix #2334
9394
_obsoleteFunctions.push_back(std::make_pair("index","Found obsolete function 'index'. It is recommended to use the function 'strchr' instead"));
95+
*/
96+
9497
_obsoleteFunctions.push_back(std::make_pair("rindex","Found obsolete function 'rindex'. It is recommended to use the function 'strrchr' instead"));
9598

9699
_obsoleteFunctions.push_back(std::make_pair("pthread_attr_getstackaddr","Found obsolete function 'pthread_attr_getstackaddr'.It is recommended that new applications use the 'pthread_attr_getstack' function"));

‎test/testobsoletefunctions.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class TestObsoleteFunctions : public TestFixture
4040
TEST_CASE(testgethostbyaddr);
4141
TEST_CASE(testusleep);
4242
TEST_CASE(testindex);
43+
TEST_CASE(test_qt_index); // FP when using the Qt function 'index'?
4344
TEST_CASE(testrindex);
4445

4546
// no false positives for variables
@@ -165,7 +166,16 @@ class TestObsoleteFunctions : public TestFixture
165166
" const char i = index(var, 0);\n"
166167
" return i;\n"
167168
"}\n");
168-
ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", errout.str());
169+
ASSERT_EQUALS("", errout.str());
170+
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Found obsolete function 'index'. It is recommended to use the function 'strchr' instead\n", errout.str());
171+
}
172+
173+
void test_qt_index()
174+
{
175+
check("void TDataModel::forceRowRefresh(int row) {\n"
176+
" emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n"
177+
"}\n");
178+
ASSERT_EQUALS("", errout.str());
169179
}
170180

171181
void testrindex()

0 commit comments

Comments
 (0)