From: Frank Kardel Date: Sat, 18 Aug 2007 12:59:45 +0000 (+0000) Subject: ntp_restrict.c: X-Git-Tag: NTP_4_2_4P4_RC1~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce1b58938b848ea6af2ef7f262df1c04e6878b68;p=thirdparty%2Fntp.git ntp_restrict.c: Bug 885: clarify to allow tools to pick up invariants easier. Use NULL instead of 0 with pointers. ChangeLog: document ntp_restrict.c change bk: 46c6ed41lcEV4TrhqKeGafRzHBQhxg --- diff --git a/ChangeLog b/ChangeLog index d4452e400..acb8d3613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ unsigned types cannot be less than 0 default_ai_family is a short lose trailing , from enum list + clarify ntp_restrict.c for easier automated analysis * [Bug 884] don't access recv buffers after having them passed to the free list. * [Bug 882] allow loopback interfaces to share addresses with other interfaces. diff --git a/ntpd/ntp_restrict.c b/ntpd/ntp_restrict.c index 334b538c0..473e2ce81 100644 --- a/ntpd/ntp_restrict.c +++ b/ntpd/ntp_restrict.c @@ -112,9 +112,9 @@ init_restrict(void) /* * Zero the list and put all but one on the free list */ - resfree = 0; + resfree = NULL; memset((char *)resinit, 0, sizeof resinit); - resfree6 = 0; + resfree6 = NULL; memset((char *)resinit6, 0, sizeof resinit6); for (i = 1; i < INITRESLIST; i++) { resinit[i].next = resfree; @@ -194,7 +194,7 @@ restrictions( * Work our way down from there. */ match = restrictlist; - for (rl = match->next; rl != 0 && rl->addr <= hostaddr; + for (rl = match->next; rl != NULL && rl->addr <= hostaddr; rl = rl->next) if ((hostaddr & rl->mask) == rl->addr) { if ((rl->mflags & RESM_NTPONLY) && @@ -234,7 +234,7 @@ restrictions( * Work our way down from there. */ match6 = restrictlist6; - for (rl6 = match6->next; rl6 != 0 && + for (rl6 = match6->next; rl6 != NULL && (memcmp(&(rl6->addr6), &hostaddr6, sizeof(hostaddr6)) <= 0); rl6 = rl6->next) { SET_IPV6_ADDR_MASK(&hostservaddr6, &hostaddr6, @@ -324,14 +324,14 @@ hack_restrict( * list. Else go searching for it. */ if (addr == 0) { - rlprev = 0; + rlprev = NULL; rl = restrictlist; } else { rlprev = restrictlist; rl = rlprev->next; - while (rl != 0) { + while (rl != NULL) { if (rl->addr > addr) { - rl = 0; + rl = NULL; break; } else if (rl->addr == addr) { if (rl->mask == mask) { @@ -343,11 +343,11 @@ hack_restrict( if (!(mflags & RESM_NTPONLY)) { - rl = 0; + rl = NULL; break; } } else if (rl->mask > mask) { - rl = 0; + rl = NULL; break; } } @@ -367,11 +367,11 @@ hack_restrict( } else { rlprev6 = restrictlist6; rl6 = rlprev6->next; - while (rl6 != 0) { + while (rl6 != NULL) { addr_cmp = memcmp(&rl6->addr6, &addr6, sizeof(addr6)); if (addr_cmp > 0) { - rl6 = 0; + rl6 = NULL; break; } else if (addr_cmp == 0) { mask_cmp = memcmp(&rl6->mask6, @@ -385,11 +385,11 @@ hack_restrict( if (!(mflags & RESM_NTPONLY)) { - rl6 = 0; + rl6 = NULL; break; } } else if (mask_cmp > 0) { - rl6 = 0; + rl6 = NULL; break; } } @@ -416,8 +416,8 @@ hack_restrict( * Here we add bits to the flags. If this is a * new restriction add it. */ - if (rl == 0) { - if (numresfree == 0) { + if (rl == NULL) { + if (resfree == NULL) { rl = (struct restrictlist *) emalloc(INCRESLIST * sizeof(struct @@ -463,7 +463,7 @@ hack_restrict( * Remove some bits from the flags. If we didn't * find this one, just return. */ - if (rl != 0) { + if (rl != NULL) { if ((rl->flags ^ (u_short)flags) & RES_LIMITED) { res_limited_refcnt--; @@ -481,7 +481,7 @@ hack_restrict( * found one. Don't remove the default entry and * don't remove an interface entry. */ - if (rl != 0 + if (rl != NULL && rl->addr != htonl(INADDR_ANY) && !(rl->mflags & RESM_INTERFACE && op != RESTRICT_REMOVEIF)) { if (rlprev != NULL) { @@ -514,8 +514,8 @@ hack_restrict( * Here we add bits to the flags. If this is a * new restriction add it. */ - if (rl6 == 0) { - if (numresfree6 == 0) { + if (rl6 == NULL) { + if (resfree6 == NULL) { rl6 = (struct restrictlist6 *)emalloc( INCRESLIST * sizeof(struct @@ -560,7 +560,7 @@ hack_restrict( * Remove some bits from the flags. If we didn't * find this one, just return. */ - if (rl6 != 0) { + if (rl6 != NULL) { if ((rl6->flags ^ (u_short)flags) & RES_LIMITED) { res_limited_refcnt6--; @@ -578,7 +578,7 @@ hack_restrict( * found one. Don't remove the default entry and * don't remove an interface entry. */ - if (rl6 != 0 && + if (rl6 != NULL && !IN6_IS_ADDR_UNSPECIFIED(&rl6->addr6) && !(rl6->mflags & RESM_INTERFACE && op != RESTRICT_REMOVEIF)) { if (rlprev6 != NULL) {