Fix some integer overflow issues reported by Coverity

This commit is contained in:
Tim Wojtulewicz 2025-07-21 15:25:48 -07:00
parent 2da3b3a2a6
commit 2e5db823ef
2 changed files with 4 additions and 4 deletions

View file

@ -162,7 +162,7 @@ void IPAddr::Mask(int top_bits_to_keep) {
if ( res.quot < 4 ) if ( res.quot < 4 )
mask_bits[res.quot] = htonl(mask_bits[res.quot] & ~bit_mask32(32 - res.rem)); mask_bits[res.quot] = htonl(mask_bits[res.quot] & ~bit_mask32(32 - res.rem));
for ( unsigned int i = res.quot + 1; i < 4; ++i ) for ( size_t i = res.quot + 1; i < 4; ++i )
mask_bits[i] = 0; mask_bits[i] = 0;
uint32_t* p = reinterpret_cast<uint32_t*>(in6.s6_addr); uint32_t* p = reinterpret_cast<uint32_t*>(in6.s6_addr);
@ -183,7 +183,7 @@ void IPAddr::ReverseMask(int top_bits_to_chop) {
if ( res.quot < 4 ) if ( res.quot < 4 )
mask_bits[res.quot] = htonl(bit_mask32(32 - res.rem)); mask_bits[res.quot] = htonl(bit_mask32(32 - res.rem));
for ( unsigned int i = res.quot + 1; i < 4; ++i ) for ( size_t i = res.quot + 1; i < 4; ++i )
mask_bits[i] = 0xffffffff; mask_bits[i] = 0xffffffff;
uint32_t* p = reinterpret_cast<uint32_t*>(in6.s6_addr); uint32_t* p = reinterpret_cast<uint32_t*>(in6.s6_addr);

View file

@ -832,7 +832,7 @@ void set_processing_status(const char* status, const char* reason) {
auto write_str = [](int fd, const char* s) { auto write_str = [](int fd, const char* s) {
int len = strlen(s); int len = strlen(s);
while ( len ) { while ( len ) {
int n = write(fd, s, len); ssize_t n = write(fd, s, len);
if ( n < 0 && errno != EINTR && errno != EAGAIN ) if ( n < 0 && errno != EINTR && errno != EAGAIN )
// Ignore errors, as they're too difficult to // Ignore errors, as they're too difficult to
@ -1882,7 +1882,7 @@ uint64_t calculate_unique_id(size_t pool) {
bool safe_write(int fd, const char* data, int len) { bool safe_write(int fd, const char* data, int len) {
while ( len > 0 ) { while ( len > 0 ) {
int n = write(fd, data, len); ssize_t n = write(fd, data, len);
if ( n < 0 ) { if ( n < 0 ) {
if ( errno == EINTR ) if ( errno == EINTR )