Menu

significance of adding include files?

Dinesh
2016-06-13
2016-06-20
  • Dinesh

    Dinesh - 2016-06-13

    Hi ,
    I am using cppcheck 1.68.
    i am facing a problem. i am using cppcheck for about 20k files.
    i found some error while analysing , its about "arrayIndexOutOfBounds".
    Even though i include a header corresponding to this error , still it reports the same error.
    To analyse it a bit further , i wrote a sample program and complied and executed it. this program executed well.

    sample.c

    #include<stdio.h>
    #include"sample.h"
    int main(){
        sid s1=10;
        name e1="";
        e1[1]='D'; // <---
        printf("print:::%c",e1[1]); // <---
        printf("\nend");
        return 0;
    }
    

    sample.h

    #include<stdio.h>
    typedef char name[10]; // <---
    typedef int sid;
    
    void printme(char *);
    void printme(char* name){
        printf("Printing Name:%s",name);
    }
    

    and i issue the cppcheck command as below:

    /opt/cppcheck_instd/Linux_x86_64/cppcheck/bin/cppcheck --xml --xml-version=2 --suppress=missingIncludeSystem --enable=all -I/bl4module4/bl4mod4/Dinesh/tmo/ /bl4module4/bl4mod4/Dinesh/tmo/sample.c 2> /bl4module4/bl4mod4/Dinesh/tmo/cppcheck_rep.xml
    

    and the report is as cppcheck_rep.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <results version="2">
        <cppcheck version="1.68"/>
        <errors>
            <error id="unreadVariable" severity="style" msg="Variable &apos;s1&apos; is assigned a value that is never used." verbose="Variable &apos;s1&apos; is assigned a value that is never used.">
                <location file="/bl4module4/bl4mod4/Dinesh/tmo/sample.c" line="5"/>
            </error>
            <error id="arrayIndexOutOfBounds" severity="error" msg="Array &apos;e1[1]&apos; accessed at index 1, which is out of bounds." verbose="Array &apos;e1[1]&apos; accessed at index 1, which is out of bounds.">
                <location file="/bl4module4/bl4mod4/Dinesh/tmo/sample.c" line="7"/>
            </error>
            <error id="arrayIndexOutOfBounds" severity="error" msg="Array &apos;e1[1]&apos; accessed at index 1, which is out of bounds." verbose="Array &apos;e1[1]&apos; accessed at index 1, which is out of bounds.">
                <location file="/bl4module4/bl4mod4/Dinesh/tmo/sample.c" line="8"/>**
            </error>
        </errors>
    </results>
    

    PLease note the error arrayIndexOutOfBounds, i have declared the name which is of size of 10 in sample.h header, but even though after including the header details in the cppcheck execution , this error is being reported .

    is that i am doing anything wrong above?
    please clarify.

    Regards,
    Dinesh

     

    Last edit: Daniel Marjamäki 2016-06-20
  • Daniel Marjamäki

    Thanks!

    it is a bug in cppcheck.

    Can you please report this in our bug tracker so we don't forget it?

    http://trac.cppcheck.net

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.