diff --git a/src/store.c b/src/store.c index eac472d..82e7a66 100644 --- a/src/store.c +++ b/src/store.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -567,18 +568,19 @@ bool cs_snip_iter(struct ref_guard *guard, enum cs_iter_direction direction, } struct cs_snip *start = guard->cs->snips; - - // cppcheck-suppress [constVariablePointer,unmatchedSuppression] - // TODO: False positive? Report upstream - struct cs_snip *end = start + guard->cs->header->nr_snips; - + ptrdiff_t idx, nr_snips = (ptrdiff_t)guard->cs->header->nr_snips; if (*snip) { - *snip = *snip + (direction == CS_ITER_NEWEST_FIRST ? -1 : 1); + ptrdiff_t cur_idx = *snip - start; + idx = cur_idx + (direction == CS_ITER_NEWEST_FIRST ? -1 : 1); } else { - *snip = direction == CS_ITER_NEWEST_FIRST ? end - 1 : start; + idx = direction == CS_ITER_NEWEST_FIRST ? nr_snips - 1 : 0; } - return *snip >= start && *snip < end; + if (idx >= 0 && idx < nr_snips) { + *snip = start + idx; + return true; + } + return false; } /**