Add a missing null-check, turning a segfault into an assertion.

Static analysis says:
src\tcp_address.cpp(297): error V595: The 'res' pointer was utilized before it was verified against nullptr. Check lines: 297, 301.
src\tcp_address.cpp(603): error V106: Implicit type conversion third argument 'full_bytes' of function 'memcmp' to memsize type.
src\tcp_address.cpp(603): error V526: The 'memcmp' function returns 0 if corresponding buffers are equal. Consider examining the condition for mistakes.

In fact the use of "memcmp" is correct, but the enclosing "if" isn't
necessary, and the compiler is happier if "full_bytes" is a size_t.
This commit is contained in:
Arthur O'Dwyer 2012-08-24 16:38:46 -07:00
parent 6347d392fd
commit 537a802788

View File

@ -294,11 +294,11 @@ int zmq::tcp_address_t::resolve_interface (const char *interface_,
}
// Use the first result.
zmq_assert (res != NULL);
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address));
memcpy (&address, res->ai_addr, res->ai_addrlen);
// Cleanup getaddrinfo after copying the possibly referenced result.
if (res)
freeaddrinfo (res);
return 0;
@ -598,11 +598,9 @@ const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, co
}
if (address_mask < mask) mask = address_mask;
int full_bytes = mask / 8;
if (full_bytes) {
size_t full_bytes = mask / 8;
if (memcmp(our_bytes, their_bytes, full_bytes))
return false;
}
uint8_t last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU;
if (last_byte_bits) {