Opened 5 years ago

Closed 5 years ago

#9548 closed Bugs (fixed)

Improper order of operations in function causing infinite recursive call

Reported by: rtrieu@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.55.0 Severity: Problem
Keywords: Cc: gromer@…

Description

In also/ip/resolver_query_base.hpp, the enum flags has an overloaded function for the ~ operator. Here is the code below:

friend flags operator~(flags x) {

return static_cast<flags>(static_cast<unsigned int>(~x));

}

Note that the ~ in the function is applied to x, not the static_cast. This will call the overloaded operator again. The proper fix is:

friend flags operator~(flags x) {

return static_cast<flags>(~static_cast<unsigned int>(x));

}

which uses the builtin ~ operator for unsigned int. This was detected by Clang's new warning -Winfinite-recursion.

Change History (2)

comment:1 Changed 5 years ago by gromer@…

Cc: gromer@… added

comment:2 Changed 5 years ago by chris_kohlhoff

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.