From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Marek Lindner Date: Thu, 5 Apr 2012 22:59:38 +0300 References: <201203222250.31309.lindner_marek@yahoo.de> <1332453075-27999-2-git-send-email-lindner_marek@yahoo.de> <20120323205212.GF5662@lunn.ch> In-Reply-To: <20120323205212.GF5662@lunn.ch> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201204052259.38938.lindner_marek@yahoo.de> Subject: Re: [B.A.T.M.A.N.] [RFC 2/5] batman-adv: ELP - creating neighbor structures, updating LQs Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: The list for a Better Approach To Mobile Ad-hoc Networking On Friday, March 23, 2012 22:52:12 Andrew Lunn wrote: > > +/* extract my own tq to neighbor from the elp packet */ > > +static uint8_t bat_v_elp_fetch_tq(uint8_t *my_iface_addr, > > + struct batman_elp_packet *elp_packet, > > + int elp_packet_len) > > +{ > > + struct elp_neigh_entry *elp_neigh_entry; > > + uint8_t tq = 0; > > + int i; > > + > > + elp_neigh_entry = (struct elp_neigh_entry *)(elp_packet + 1); > > + elp_packet_len -= BATMAN_ELP_HLEN; > > + > > + for (i = 0; i < elp_packet->num_neighbors; i++) { > > + if (!compare_eth(my_iface_addr, elp_neigh_entry->addr)) > > + goto next; > > + > > + tq = elp_neigh_entry->rq; > > + break; > > + > > + next: > > + elp_packet_len -= sizeof(struct elp_neigh_entry); > > + if (elp_packet_len < 0) > > + break; > > + > > + elp_neigh_entry++; > > + } > > I'm personally not a fan of using goto like this. Reminds me of BASIC. > > Could this be changed? Maybe first validate elp_packet->num_neighbors > matches the packet length, and then skip elp_packet_len check in each > iteration of the loop. A normal if then else should then be possible. Something like this ? elp_packet_len -= BATMAN_ELP_HLEN; elp_packet_len -= elp_packet->num_neighbors * sizeof(struct elp_neigh_entry; if (elp_packet_len < 0) return; Cheers, Marek