Skip to content

Fix 14956: FP arrayIndexOutOfBounds with break in loop - #8772

Open
pfultz2 wants to merge 3 commits into
cppcheck-opensource:mainfrom
pfultz2:valueflow-skip-unconditional-break
Open

Fix 14956: FP arrayIndexOutOfBounds with break in loop#8772
pfultz2 wants to merge 3 commits into
cppcheck-opensource:mainfrom
pfultz2:valueflow-skip-unconditional-break

Conversation

@pfultz2

@pfultz2 pfultz2 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread test/testbufferoverrun.cpp
@aadanen

aadanen commented Aug 5, 2026

Copy link
Copy Markdown

I wonder if we could catch cases like this as well:

int s[5];
void f()
{
  short i;
  for (i = 0; 1; i++)
  {
    if ( i == 4 )
      break;
  }
  s[i] = 0;
}

which currently produces

break.c:10:3: error: Array 's[5]' accessed at index 9999, which is out of bounds. [arrayIndexOutOfBounds]
 s[i] = 0;
  ^
break.c:5:2: note: After for loop, i has value 9999
 for (i = 0; 1; i++)
 ^
break.c:10:3: note: Array index out of bounds
 s[i] = 0;

@danmar

danmar commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

which currently produces

that is a false positive! @pfultz2 I assume a ticket should be created? I can create it unless you feel you will fix it in this PR..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants