From: Shawn Routhier Date: Tue, 2 Feb 2010 00:44:06 +0000 (+0000) Subject: Clean up some compiler warnings X-Git-Tag: v4_2_0b1~3^2~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a35285748d900c9bc65cf57f99bdc548e626171e;p=thirdparty%2Fdhcp.git Clean up some compiler warnings --- diff --git a/common/options.c b/common/options.c index bc3282fd0..52003ab6f 100644 --- a/common/options.c +++ b/common/options.c @@ -3782,13 +3782,13 @@ packet6_len_okay(const char *packet, int len) { } if ((packet[0] == DHCPV6_RELAY_FORW) || (packet[0] == DHCPV6_RELAY_REPL)) { - if (len >= sizeof(struct dhcpv6_relay_packet)) { + if (len >= offsetof(struct dhcpv6_relay_packet, options)) { return 1; } else { return 0; } } else { - if (len >= sizeof(struct dhcpv6_packet)) { + if (len >= offsetof(struct dhcpv6_packet, options)) { return 1; } else { return 0; diff --git a/configure.ac b/configure.ac index 2af548c41..707137f45 100644 --- a/configure.ac +++ b/configure.ac @@ -508,6 +508,8 @@ CFLAGS="$CFLAGS $STD_CWARNINGS" # Try to add the bind include directory CFLAGS="$CFLAGS -I$libbind/include" +AC_C_FLEXIBLE_ARRAY_MEMBER + AC_OUTPUT([ Makefile client/Makefile diff --git a/includes/dhcp6.h b/includes/dhcp6.h index 36c1535b0..03db160e9 100644 --- a/includes/dhcp6.h +++ b/includes/dhcp6.h @@ -177,7 +177,7 @@ extern const int dhcpv6_type_name_max; struct dhcpv6_packet { unsigned char msg_type; unsigned char transaction_id[3]; - unsigned char options[0]; + unsigned char options[FLEXIBLE_ARRAY_MEMBER]; }; /* Offset into DHCPV6 Reply packets where Options spaces commence. */ @@ -191,7 +191,7 @@ struct dhcpv6_relay_packet { unsigned char hop_count; unsigned char link_address[16]; unsigned char peer_address[16]; - unsigned char options[0]; + unsigned char options[FLEXIBLE_ARRAY_MEMBER]; }; /* Leasequery query-types (RFC 5007) */ diff --git a/omapip/hash.c b/omapip/hash.c index bace3cd4d..e33f803e0 100644 --- a/omapip/hash.c +++ b/omapip/hash.c @@ -297,23 +297,27 @@ do_id_hash(const void *name, unsigned len, unsigned size) if (len == 0) return 0; - /* The switch indexes our starting position into the do/while loop, - * taking up the remainder after hashing in all the other bytes in - * threes. + /* + * The switch handles our starting conditions, then we hash the + * remaining bytes in groups of 3 */ + switch (len % 3) { - do { - case 0: - accum ^= *s++ << 16; - case 2: - accum ^= *s++ << 8; - case 1: - accum ^= *s++; - } while (s < end); - + case 0: + break; + case 2: + accum ^= *s++ << 8; + case 1: + accum ^= *s++; break; } + while (s < end) { + accum ^= *s++ << 16; + accum ^= *s++ << 8; + accum ^= *s++; + } + return accum % size; } diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c index 0bed393c5..53651b640 100644 --- a/relay/dhcrelay.c +++ b/relay/dhcrelay.c @@ -1355,7 +1355,7 @@ process_up6(struct packet *packet, struct stream_list *dp) { /* Build the relay-forward header. */ relay = (struct dhcpv6_relay_packet *) forw_data; - cursor = sizeof(*relay); + cursor = offsetof(struct dhcpv6_relay_packet, options); relay->msg_type = DHCPV6_RELAY_FORW; if (packet->dhcpv6_msg_type == DHCPV6_RELAY_FORW) { if (packet->dhcpv6_hop_count >= max_hop_count) { @@ -1483,7 +1483,7 @@ process_down6(struct packet *packet) { if (!evaluate_option_cache(&relay_msg, packet, NULL, NULL, packet->options, NULL, &global_scope, oc, MDL) || - (relay_msg.len < sizeof(struct dhcpv6_packet))) { + (relay_msg.len < offsetof (struct dhcpv6_packet, options))) { log_error("Can't evaluate relay-msg."); return; } diff --git a/server/dhcp.c b/server/dhcp.c index f49cee38f..3601bd1ac 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -3423,7 +3423,6 @@ int find_lease (struct lease **lp, piaddr (hw_lease -> ip_addr)); #endif goto n_hw; - continue; } if (hw_lease -> subnet -> shared_network != share) { #if defined (DEBUG_FIND_LEASE) @@ -3431,7 +3430,6 @@ int find_lease (struct lease **lp, piaddr (hw_lease -> ip_addr)); #endif goto n_hw; - continue; } if ((hw_lease -> pool -> prohibit_list && permitted (packet, hw_lease -> pool -> prohibit_list)) || diff --git a/server/dhcpv6.c b/server/dhcpv6.c index 6ad7681e9..5cd7c4bc1 100644 --- a/server/dhcpv6.c +++ b/server/dhcpv6.c @@ -4226,7 +4226,7 @@ dhcpv6_confirm(struct data_string *reply_ret, struct packet *packet) { isc_boolean_t inappropriate, has_addrs; char reply_data[65536]; struct dhcpv6_packet *reply = (struct dhcpv6_packet *)reply_data; - int reply_ofs = (int)((char *)reply->options - (char *)reply); + int reply_ofs = (int)(offsetof(struct dhcpv6_packet, options)); /* * Basic client message validation. @@ -4583,7 +4583,7 @@ iterate_over_ia_na(struct data_string *reply_ret, int iaaddr_is_found; char reply_data[65536]; struct dhcpv6_packet *reply = (struct dhcpv6_packet *)reply_data; - int reply_ofs = (int)((char *)reply->options - (char *)reply); + int reply_ofs = (int)(offsetof(struct dhcpv6_packet, options)); char status_msg[32]; struct iasubopt *lease; struct ia_xx *existing_ia_na; @@ -5555,7 +5555,7 @@ dhcpv6_relay_forw(struct data_string *reply_ret, struct packet *packet) { sizeof(reply->link_address)); memcpy(reply->peer_address, &packet->dhcpv6_peer_address, sizeof(reply->peer_address)); - reply_ofs = (int)((char *)reply->options - (char *)reply); + reply_ofs = (int)(offsetof(struct dhcpv6_relay_packet, options)); /* * Get the reply option state. diff --git a/server/mdb6.c b/server/mdb6.c index 31a8dfcc4..bbd671f47 100644 --- a/server/mdb6.c +++ b/server/mdb6.c @@ -30,14 +30,14 @@ #include HASH_FUNCTIONS(ia, unsigned char *, struct ia_xx, ia_hash_t, - ia_reference, ia_dereference, do_string_hash); + ia_reference, ia_dereference, do_string_hash) ia_hash_t *ia_na_active; ia_hash_t *ia_ta_active; ia_hash_t *ia_pd_active; HASH_FUNCTIONS(iasubopt, struct in6_addr *, struct iasubopt, iasubopt_hash_t, - iasubopt_reference, iasubopt_dereference, do_string_hash); + iasubopt_reference, iasubopt_dereference, do_string_hash) struct ipv6_pool **pools; int num_pools; diff --git a/server/omapi.c b/server/omapi.c index c9dbb254f..262943524 100644 --- a/server/omapi.c +++ b/server/omapi.c @@ -1891,7 +1891,12 @@ class_set_value (omapi_object_t *h, } else return DHCP_R_INVALIDARG; - return ISC_R_SUCCESS; + /* + * Currently no way to get here, if we update the above + * code so that we do get here this return needs to be + * uncommented. + * return ISC_R_SUCCESS; + */ }