Erroneous for loop in omapip/connection.c

Martin Robrecht Martin.Robrecht at bruker-biospin.de
Fri Feb 18 12:27:57 UTC 2011


dhcp-4.2.0-P2.tar.gz : omapip/connection.c contains following code at line 373 :

omapi_array_foreach_begin (omapi_connections,
				   omapi_connection_object_t, lp) {
	    for (i = 0; (lp -> connect_list &&
			 i < lp -> connect_list -> count); i++) {
		    if (!memcmp (&remote.sin_addr,
				 &lp -> connect_list -> addresses [i].address,
				 sizeof remote.sin_addr) &&
			(ntohs (remote.sin_port) ==
			 lp -> connect_list -> addresses [i].port))
			lp -> state = omapi_connection_connected;
			lp -> remote_addr = remote;
			lp -> remote_addr.sin_family = AF_INET;
			omapi_addr_list_dereference (&lp -> connect_list, MDL);
			lp -> index = connect_index;
			status = omapi_signal_in ((omapi_object_t *)lp,
						  "connect");
			omapi_connection_dereference (&lp, MDL);
			return;
		}
	} omapi_array_foreach_end (omapi_connections,
				   omapi_connection_object_t, lp);

The body of the for loop is executed only once because of the return statement.
I do not understand the code in detail, but I do not think that this behavior was intented.
Does anybody know what corrections are appropriate ?

Should the for loop be replaced by an if

---
	    for (i = 0; (lp -> connect_list &&
			 i < lp -> connect_list -> count); i++) {
---
	    i = 0;
	    if (lp -> connect_list && i < lp -> connect_list -> count) {
---

or should a compound statement begin after this if-statement

		    if (!memcmp (&remote.sin_addr,
				 &lp -> connect_list -> addresses [i].address,
				 sizeof remote.sin_addr) &&
			(ntohs (remote.sin_port) ==
			 lp -> connect_list -> addresses [i].port))

and end after the return statement ?

-- 
Freundliche Gruesse / Kind regards

Martin Robrecht



More information about the dhcp-users mailing list