Skip to content

Commit c6c002a

Browse files
committed
Partial fix for #14810 FN constVariablePointer (cbegin() called on container)
1 parent 89da2d1 commit c6c002a

6 files changed

Lines changed: 17 additions & 0 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ LIBOBJ = $(libcppdir)/valueflow.o \
228228
$(libcppdir)/checknullpointer.o \
229229
$(libcppdir)/checkother.o \
230230
$(libcppdir)/checkpostfixoperator.o \
231+
$(libcppdir)/checks.o \
231232
$(libcppdir)/checksizeof.o \
232233
$(libcppdir)/checkstl.o \
233234
$(libcppdir)/checkstring.o \
@@ -560,6 +561,9 @@ $(libcppdir)/checkother.o: lib/checkother.cpp lib/addoninfo.h lib/astutils.h lib
560561
$(libcppdir)/checkpostfixoperator.o: lib/checkpostfixoperator.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checkpostfixoperator.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
561562
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkpostfixoperator.cpp
562563

564+
$(libcppdir)/checks.o: lib/checks.cpp
565+
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checks.cpp
566+
563567
$(libcppdir)/checksizeof.o: lib/checksizeof.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checksizeof.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
564568
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checksizeof.cpp
565569

lib/checks.cpp

Whitespace-only changes.

lib/cppcheck.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<ClCompile Include="checknullpointer.cpp" />
5858
<ClCompile Include="checkother.cpp" />
5959
<ClCompile Include="checkpostfixoperator.cpp" />
60+
<ClCompile Include="checks.cpp" />
6061
<ClCompile Include="checksizeof.cpp" />
6162
<ClCompile Include="checkstl.cpp" />
6263
<ClCompile Include="checkstring.cpp" />
@@ -130,6 +131,7 @@
130131
<ClInclude Include="checknullpointer.h" />
131132
<ClInclude Include="checkother.h" />
132133
<ClInclude Include="checkpostfixoperator.h" />
134+
<ClInclude Include="checks.h" />
133135
<ClInclude Include="checksizeof.h" />
134136
<ClInclude Include="checkstl.h" />
135137
<ClInclude Include="checkstring.h" />

lib/library.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,8 @@ bool Library::isFunctionConst(const Token *ftok) const
17811781
const Yield yield = astContainerYield(ftok->astParent()->astOperand1(), *this);
17821782
if (yield == Yield::EMPTY || yield == Yield::SIZE || yield == Yield::BUFFER_NT)
17831783
return true;
1784+
if ((yield == Yield::START_ITERATOR || yield == Yield::END_ITERATOR) && ftok->str()[0] == 'c')
1785+
return true;
17841786
}
17851787
return false;
17861788
}

oss-fuzz/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ LIBOBJ = $(libcppdir)/valueflow.o \
6565
$(libcppdir)/checknullpointer.o \
6666
$(libcppdir)/checkother.o \
6767
$(libcppdir)/checkpostfixoperator.o \
68+
$(libcppdir)/checks.o \
6869
$(libcppdir)/checksizeof.o \
6970
$(libcppdir)/checkstl.o \
7071
$(libcppdir)/checkstring.o \
@@ -230,6 +231,9 @@ $(libcppdir)/checkother.o: ../lib/checkother.cpp ../lib/addoninfo.h ../lib/astut
230231
$(libcppdir)/checkpostfixoperator.o: ../lib/checkpostfixoperator.cpp ../lib/addoninfo.h ../lib/check.h ../lib/checkers.h ../lib/checkpostfixoperator.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/regex.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
231232
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkpostfixoperator.cpp
232233

234+
$(libcppdir)/checks.o: ../lib/checks.cpp
235+
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checks.cpp
236+
233237
$(libcppdir)/checksizeof.o: ../lib/checksizeof.cpp ../lib/addoninfo.h ../lib/check.h ../lib/checkers.h ../lib/checksizeof.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/regex.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenize.h ../lib/tokenlist.h ../lib/utils.h ../lib/vfvalue.h
234238
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checksizeof.cpp
235239

test/testother.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4823,6 +4823,11 @@ class TestOther : public TestFixture {
48234823
" return s->x ? 1 : 0;\n"
48244824
"}\n");
48254825
ASSERT_EQUALS("[test.cpp:2:10]: (style) Parameter 's' can be declared as pointer to const [constParameterPointer]\n", errout_str());
4826+
4827+
check("int f(std::vector<int>* p) {\n" // #14810
4828+
" return *p->cbegin();\n"
4829+
"}\n");
4830+
ASSERT_EQUALS("[test.cpp:1:25]: (style) Parameter 'p' can be declared as pointer to const [constParameterPointer]\n", errout_str());
48264831
}
48274832

48284833
void constArray() {

0 commit comments

Comments
 (0)