* [patch/iputils] use proper loop constructs rather than goto's
@ 2006-12-20 15:17 Mike Frysinger
0 siblings, 0 replies; only message in thread
From: Mike Frysinger @ 2006-12-20 15:17 UTC (permalink / raw)
To: netdev
[-- Attachment #1.1: Type: text/plain, Size: 430 bytes --]
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 #1.2: Type: application/pgp-signature, Size: 189 bytes --]
[-- Attachment #2: iputils-use-proper-loops.patch --]
[-- Type: text/x-diff, Size: 2594 bytes --]
use proper looping code rather than labels/gotos as some versions of
gcc may miscompile the code.
Signed-off-by: Robert Moss <robmoss@gentoo.org>
Signed-off-by: Mike Frysinger <robmoss@gentoo.org>
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;
}
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-20 15:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-20 15:17 [patch/iputils] use proper loop constructs rather than goto's Mike Frysinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).