try to fix bug with spurious "everything is broken" warning

svn:r5994
This commit is contained in:
Nick Mathewson 2006-02-13 00:26:43 +00:00
parent e20df524b9
commit 2cc66125b8
2 changed files with 11 additions and 2 deletions

View File

@ -1426,8 +1426,12 @@ int
addr_mask_get_bits(uint32_t mask)
{
int i;
if (mask == 0)
return 0;
if (mask == 0xFFFFFFFFu)
return 32;
for (i=0; i<=32; ++i) {
if (mask == ~((1<<(32-i))-1)) {
if (mask == (uint32_t) ~((1u<<(32-i))-1)) {
return i;
}
}
@ -1493,7 +1497,7 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
"Bad number of mask bits on address range; rejecting.");
goto err;
}
*mask_out = ~((1<<(32-bits))-1);
*mask_out = ~((1u<<(32-bits))-1);
} else if (tor_inet_aton(mask, &in) != 0) {
*mask_out = ntohl(in.s_addr);
} else {

View File

@ -835,6 +835,11 @@ test_util(void)
test_eq(u32, 0x7f000001u);
test_eq(u16, 0);
tor_free(cp);
test_eq(0, addr_mask_get_bits(0x0u));
test_eq(32, addr_mask_get_bits(0xFFFFFFFFu));
test_eq(16, addr_mask_get_bits(0xFFFF0000u));
test_eq(31, addr_mask_get_bits(0xFFFFFFFEu));
test_eq(1, addr_mask_get_bits(0x80000000u));
/* Test tor_parse_long. */
test_eq(10L, tor_parse_long("10",10,0,100,NULL,NULL));