Menu

Code mistaken as divide by zero

Lou Cyphre
2024-11-05
2024-11-08
  • Lou Cyphre

    Lou Cyphre - 2024-11-05

    Given the following code, and a generated warning

    static int64_t  floor_divn(int64_t x_in, int64_t y_in)
    {
        int64_t x = x_in;
        int64_t y = y_in;
        int64_t quot = INT64_MAX;
    
        if (y != 0)
        {
            if ((x > 0) && (y < 0))
            {
                x = -x;
                y = -y;
            }
    
            if ((x < 0) && (y > 0))
            {
                x = x - y + 1;
            }
    
            quot = x / y;   // warning: Either the condition 'y>0' is redundant or 
                            // there is division by zero at line ... [zerodivcond]
        }
        return  quot;
    }
    

    to me it looks like none of the two hypothesis for a warning is true

     
  • CHR

    CHR - 2024-11-08

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/13292

     

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.