Skip to contentSkip to conversation

use proper loop constructs rather than goto's

patch/iputils Mike Frysinger 1 participant 1 message Dec 20, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

a bunch of places in the tracepath code use goto's rather than real loop code, or goto's to jump out of loop's ... some versions (like gcc-3.3.x iirc, older admittedly) would miscompile this and it's cleaner anyways to just use real loops

the attached patch isnt applicable as is (style changes required mostly) as i just want to see if people will accept it or the answer is "upgrade your gcc to like 4.1.x"
-mike

use proper looping code rather than labels/gotos as some versions of gcc may miscompile the code.

tracepath.c +5 -5
index c3f6f74..7ff85a2 100644
@@ -77,7 +77,7 @@ int recverr(int fd, int ttl)
 	int progress = -1;
 	int broken_router;
 	
-restart:
+       while (1) {
 	memset(&rcvbuf, -1, sizeof(rcvbuf));
 	iov.iov_base = &rcvbuf;
 	iov.iov_len = sizeof(rcvbuf);
@@ -94,7 +94,7 @@ restart:
 	if (res < 0) {
 		if (errno == EAGAIN)
 			return progress;
-		goto restart;
+		continue;
 	}
 
 	progress = mtu;
@@ -217,7 +217,7 @@ restart:
 		perror("NET ERROR");
 		return 0;
 	}
-	goto restart;
+       }
 }
 
 int probe_ttl(int fd, int ttl)
@@ -228,7 +228,6 @@ int probe_ttl(int fd, int ttl)
 
 	memset(sndbuf,0,mtu);
 
-restart:
 	for (i=0; i<10; i++) {
 		int res;
 
@@ -244,7 +243,8 @@ restart:
 		if (res==0)
 			return 0;
 		if (res > 0)
-			goto restart;
+			i = 0;
+			continue;
 	}
 	hisptr = (hisptr + 1)&63;
 
tracepath6.c +19 -24

74 lines not on this page · raw message