[Bug pending/80744] New: Detect Divide By Zero and give a warning in C/C++

jg at jguk dot org gcc-bugzilla@gcc.gnu.org
Mon May 15 01:55:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80744

            Bug ID: 80744
           Summary: Detect Divide By Zero and give a warning in  C/C++
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: pending
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Could GCC be expanded for -Wdiv-by-zero to detect these?

$200 bounty

// (A), (B) and (C) should give "warning: unsafe, may divide by zero
// (D) is from a const, NB shouldn't give a warning
void test_func(const size_t value, const string & mystr)
{
    const size_t i = 0;
    const size_t j = 1;

    printf("A %zu mystr\n", 5 / mystr.size());

    printf("B %zu\n", 10/i);

    printf("C %zu\n", i/value);

    printf("D %zu\n", 10/j);
}


More information about the Gcc-bugs mailing list