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

Attachment: pgpNH4BfJuLjf.pgp
Description: PGP signature

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

Signed-off-by: Robert Moss <[EMAIL PROTECTED]>
Signed-off-by: Mike Frysinger <[EMAIL PROTECTED]>

diff --git a/tracepath.c b/tracepath.c
index c3f6f74..7ff85a2 100644
--- a/tracepath.c
+++ b/tracepath.c
@@ -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;
 
diff --git a/tracepath6.c b/tracepath6.c
index 23d6a8c..6d2a95b 100644
--- a/tracepath6.c
+++ b/tracepath6.c
@@ -71,7 +71,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);
@@ -88,7 +88,7 @@ restart:
 	if (res < 0) {
 		if (errno == EAGAIN)
 			return progress;
-		goto restart;
+		continue;
 	}
 
 	progress = 2;
@@ -233,34 +233,29 @@ restart:
 		perror("NET ERROR");
 		return 0;
 	}
-	goto restart;
+       }
 }
 
 int probe_ttl(int fd, int ttl)
 {
-	int i;
+	int i=0, res;
 	char sndbuf[mtu];
 	struct probehdr *hdr = (struct probehdr*)sndbuf;
 
-restart:
-
-	for (i=0; i<10; i++) {
-		int res;
-
-		hdr->ttl = ttl;
-		gettimeofday(&hdr->tv, NULL);
-		if (send(fd, sndbuf, mtu-overhead, 0) > 0)
-			break;
-		res = recverr(fd, ttl);
-		if (res==0)
-			return 0;
-		if (res > 0)
-			goto restart;
-	}
-
-	if (i<10) {
-		int res;
-
+	while (i<10) {
+		for (i=0; i<10; i++) {
+			hdr->ttl = ttl;
+			gettimeofday(&hdr->tv, NULL);
+			if (send(fd, sndbuf, mtu-overhead, 0) > 0)
+				break;
+			res = recverr(fd, ttl);
+			if (res==0)
+				return 0;
+			if (res > 0) {
+				i = 0;
+				continue;
+			}
+		}
 		data_wait(fd);
 		if (recv(fd, sndbuf, sizeof(sndbuf), MSG_DONTWAIT) > 0) {
 			printf("%2d?: reply received 8)\n", ttl);
@@ -268,7 +263,7 @@ restart:
 		}
 		res = recverr(fd, ttl);
 		if (res == 1)
-			goto restart;
+			continue;
 		return res;
 	}
 

Reply via email to