From: Marcin Siodelski Date: Wed, 18 Feb 2015 11:57:38 +0000 (+0100) Subject: [3711] Simplify the logic in the IOAddress::substract. X-Git-Tag: trac3723_base~18^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b811723edb583945b202aafffdab80877f96c950;p=thirdparty%2Fkea.git [3711] Simplify the logic in the IOAddress::substract. --- diff --git a/src/lib/asiolink/io_address.cc b/src/lib/asiolink/io_address.cc index 827793bf1e..07bc17c4cd 100644 --- a/src/lib/asiolink/io_address.cc +++ b/src/lib/asiolink/io_address.cc @@ -156,14 +156,9 @@ IOAddress::subtract(const IOAddress& a, const IOAddress& b) { uint8_t carry = 0; // Now perform subtraction with borrow. - for (int i = 15; i >=0; --i) { - if (a_vec[i] >= (b_vec[i] + carry) ) { - result[i] = a_vec[i] - b_vec[i] - carry; - carry = 0; - } else { - result[i] = a_vec[i] - b_vec[i] - carry; - carry = 1; - } + for (int i = a_vec.size() - 1; i >= 0; --i) { + result[i] = a_vec[i] - b_vec[i] - carry; + carry = (a_vec[i] < b_vec[i] + carry); } return (fromBytes(AF_INET6, &result[0])); @@ -172,10 +167,6 @@ IOAddress::subtract(const IOAddress& a, const IOAddress& b) { IOAddress IOAddress::increase(const IOAddress& addr) { - // Since the same array will be used to hold the IPv4 and IPv6 - // address we have to make sure that the size of the array - // we allocate will work for both types of address. - BOOST_STATIC_ASSERT(V4ADDRESS_LEN <= V6ADDRESS_LEN); std::vector packed(addr.toBytes()); // Start increasing the least significant byte