$cppchecktest_incr_bound.cppCheckingtest_incr_bound.cpp...test_incr_bound.cpp:13:6:error:Array'v[4]'accessedatindex5,whichisoutofbounds.[arrayIndexOutOfBounds]v[idx++].set(0);^test_incr_bound.cpp:9:15:note:Assignment'idx=0',assignedvalueis0intidx=0;^test_incr_bound.cpp:11:7:note:idxisincremented', new value is 1 v[idx++].set(0); ^test_incr_bound.cpp:11:7: note: idx is incremented',newvalueis2v[idx++].set(0);^test_incr_bound.cpp:12:7:note:idxisincremented', new value is 3 v[idx++].set(0); ^test_incr_bound.cpp:12:7: note: idx is incremented',newvalueis4v[idx++].set(0);^test_incr_bound.cpp:13:7:note:idxisincremented', new value is 5 v[idx++].set(0); ^test_incr_bound.cpp:13:6: note: Array index out of bounds v[idx++].set(0); ^test_incr_bound.cpp:14:6: error: Array 'v[4]' accessed at index 7, which is out of bounds. [arrayIndexOutOfBounds] v[idx++].set(0); ^test_incr_bound.cpp:9:15: note: Assignment 'idx=0', assigned value is 0 int idx = 0; ^test_incr_bound.cpp:11:7: note: idx is incremented',newvalueis1v[idx++].set(0);^test_incr_bound.cpp:11:7:note:idxisincremented', new value is 2 v[idx++].set(0); ^test_incr_bound.cpp:12:7: note: idx is incremented',newvalueis3v[idx++].set(0);^test_incr_bound.cpp:12:7:note:idxisincremented', new value is 4 v[idx++].set(0); ^test_incr_bound.cpp:13:7: note: idx is incremented',newvalueis5v[idx++].set(0);^test_incr_bound.cpp:13:7:note:idxisincremented', new value is 6 v[idx++].set(0); ^test_incr_bound.cpp:14:7: note: idx is incremented',newvalueis7v[idx++].set(0);^test_incr_bound.cpp:14:6:note:Arrayindexoutofboundsv[idx++].set(0);^$cppcheck--versionCppcheck2.13.0$
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Guys,
It looks like increment is evaluated twice ... do you know of this issue ?
change from post to pre-increment does not change anything.
if I change to
v[idx++].a =0;
then it's ok, but as soon as I called a member function, it goes awry.
logs:
Thanks for reporting, added here: https://trac.cppcheck.net/ticket/12731
from the trac link, I thought the issue was corrected in 2.17.1 version... but It's still occurs.
Did I misunderstand or does the defect fall into limbo ?
(just asking !) Regards.
The ticket is still open, so unfortunately nothing has been fixed yet.
Last edit: CHR 2025-04-05