Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:40:06+00:00 2026-06-09T17:40:06+00:00

I installed the Cppcheck tool for static code analysis of my C++ project and

  • 0

I installed the Cppcheck tool for static code analysis of my C++ project and got the feeling that it performs poorly. For example, can anyone tell me why Cppcheck is unable to find an array out-of-bounds error in the following code?

void f(int c) { 
    char *p = new char[10]; 
    p[c] = 42; 
} 

void g() { 
    f(100); 
} 

There’s an online demo where this code can be conveniently checked using Cppcheck. All it comes up with is a memory leak at line 4, no signs of a potential buffer overflow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:40:08+00:00Added an answer on June 9, 2026 at 5:40 pm

    Because it is not supported currently.

    This is actually not an obvious error to the compiler. Something like

    char c[5];
    for (int i=0; i<10; ++i)
        c[i] = 0;
    

    is more obvious, as it is all in the same code.

    Something like

    #define f(c) { \
        char *p = new char[10];  \
        p[c] = 42; \
    }
    
    void g() { 
        f(100); 
    } 
    

    is more obvious, because cppcheck and the compiler expand all macros in-place before actual checks.

    However, your posted code is not trivial, because cppcheck as well as the compiler need the whole code inside that function and evaluate it with respect to the parameter. It is of course possible if the function is in sight (it becomes pretty hard, up to impossible, across translation units), but right now, cppcheck does not have that feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed Python 3.0 and now I can't get my code to work. Does
Installed a fresh Delphi xe2. Open a new project (vcl forms application). opened the
I installed the latest versions of SDK (API 16) and got the latest ADT.
I installed hadoop 1.0.0 and tried out word counting example (single node cluster). It
I installed with NuGet the packages NHibernate and Castle.Core 3.0 for a new project.
Installed Magento 1.6.2.0, and noticed that the links are like http://MYSEUPERSTORE.com/ index.php /customer/account/ but
Installed latest SDK updates from Google and my project changed to target 2.1 I
I installed m2eclipse plugin. I want to create pom.xml in my project which is
I installed win32api and can import and make calls to it from the command
I installed the wxWidgets source code, compiled it and am linking the libraries thus

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.