Menu

False positive of divide sizeof pointer

2021-02-12
2021-02-12
  • Curtis Malainey

    Curtis Malainey - 2021-02-12

    Hello cppcheck community,

    Thanks for your wonderful tool, but I think I found an error in pointer
    checking. I am getting the following output

    /home/curtis/sof/sof/src/drivers/imx/sdma.c:258:21: warning:inconclusive:
    Division of result of sizeof() on pointer type. [divideSizeof]

      chan->index * sizeof(*pdata->ctx) / 4,
    
    
                    ^
    

    /home/curtis/sof/sof/src/drivers/imx/sdma.c:259:7: warning:inconclusive:
    Division of result of sizeof() on pointer type. [divideSizeof]

      sizeof(*pdata->ctx) / 4);
    
    
      ^
    

    /home/curtis/sof/sof/src/drivers/imx/sdma.c:275:7: warning:inconclusive:
    Division of result of sizeof() on pointer type. [divideSizeof]

      sizeof(*pdata->contexts) / 4);
    
    
      ^
    

    /home/curtis/sof/sof/src/drivers/imx/sdma.c:291:6: warning:inconclusive:
    Division of result of sizeof() on pointer type. [divideSizeof]

     sizeof(*pdata->contexts) / 4);
    

    But when you look at the code

    https://github.com/thesofproject/sof/blob/master/src/drivers/imx/sdma.c#L258

    You can see that it's doing a dereference on the pointer before calling
    sizeof.

    Removing the double dereference to just sizeof(*ctx) by creating a pointer
    variable does not silence the error either. Storing the result of the
    sizeof in a variable then dividing on another line does silence the error.

    Tested on latest 2.3 release.

    Thanks in advance.

     
  • CHR

    CHR - 2021-02-12

    Here is a reduced snippet that still gives the warning:

    struct sdma_chan {
        struct sdma_context *ctx;
    };
    
    static int sdma_upload_context(struct dma_chan_data *chan)
    {
        struct sdma_chan *pdata = dma_chan_get_data(chan);
    
        return sdma_run_c0(
                   chan->index * sizeof(*pdata->ctx) / 4,
                   sizeof(*pdata->ctx) / 4);
    }
    
     
  • CHR

    CHR - 2021-02-12

    Thanks for the report. I have created a ticket: https://trac.cppcheck.net/ticket/10179

     

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.