FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix 14956: FP arrayIndexOutOfBounds with break in loop by pfultz2 · Pull Request #8772 · cppcheck-opensource/cppcheck · GitHub

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 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

" arr[idx] = 0;\n"
"}\n");
ASSERT_EQUALS(
"[test.cpp:9:8]: (error) Array 'arr[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]\n",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi! I am new so sorry if this is a silly question.

I thought that if we want to return an error, we must be guaranteed that it is actually an error. In this input it looks like the array access is only out of bounds if c is true. Since we don't know anything about c, I thought we couldn't report any errors. I would expect the correct output for this testcase to be no errors.

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;

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL