Opened 4 years ago

#13613 new Bugs

gcd performs modulo by zero which is undefined

Reported by: James E. King, III Owned by: Daryle Walker
Milestone: To Be Determined Component: integer
Version: Boost 1.67.0 Severity: Problem
Keywords: ub Cc:

Description

Boost.Rational uses Boost.Integer's gcd method. I Added Coverity Scan support to the Boost.Rational build and it identified an issue that needs investigation:

CID 293013 (#4-12 of 12): Division or modulo by zero (DIVIDE_BY_ZERO) divide_by_zero: In function call gcd, modulo by expression 0 has undefined behavior. [hide details]

(rational_test.cpp) 470 BOOST_CHECK_EQUAL( boost::gcd<T>( 0, -9), static_cast<T>( 9) );

(rational.hpp) IntType gcd(IntType n, IntType m) {

Defer to the version in Boost.Integer

  1. divide_arg: n is used as a divisor in function gcd.

return integer::gcd( n, m );

}

Change History (0)

Note: See TracTickets for help on using tickets.