Nmap Development mailing list archives
Re: gcc-4 troubleshooting
From: Duilio Protti <dprotti () flowgate net>
Date: Mon, 29 Aug 2005 17:50:39 -0300
Fyodor wrote:
While this works for now, a better approach might be to find all the
lines that apparently violate C99 alias rules and fix them. Here is
an example that SoC student Paul Tarjan found (from tcpip.cc):
buf = (u8 *) safe_zalloc(bufsz);
[...]
ifr = (struct ifreq *) buf;
[...]
for(; ifr && *((u8 *)ifr) && ((u8 *)ifr) < buf + ifc.ifc_len;
((*(char **)&ifr) += len ))
I don't know if it is technically legal or not, but gcc doesn't seem
to like it with -O2. It is pretty gross anyway, and deserves to be
changed for that reason if no other.
An example similar to the code above can be found on a post by Marcus Brinkmann here:
http://lists.gnu.org/archive/html/l4-hurd/2005-01/msg00027.html According to Marcus, the following code is good (for aliasing rules): struct a; struct a_d { struct a a_m; int etc; }; struct a_d a_i; struct a *ap = &a_i.a_m; But this other one doesn't respect well the mentioned rules: struct a *ap = malloc (sizeof (struct a_d)); struct a_d *adp = (struct adp *) ap;With this in mind, the tcpip.cc fragment above can be changed in the form described on the attached patch.
Bye, Duilio.
--- tcpip.cc.orig 2005-08-29 15:40:32.000000000 -0300
+++ tcpip.cc 2005-08-29 16:38:22.000000000 -0300
@@ -2159,10 +2159,10 @@
struct ifconf ifc;
struct ifreq *ifr;
struct ifreq tmpifr;
+ struct ifreq *buf;
#endif
int len, rc;
char *p;
- u8 *buf;
int bufsz;
struct sockaddr_in *sin;
u16 ifflags;
@@ -2194,13 +2194,13 @@
sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0) pfatal("socket in getinterfaces");
bufsz = 20480;
- buf = (u8 *) safe_zalloc(bufsz);
+ buf = (struct ifreq *) safe_zalloc(bufsz);
ifc.ifc_len = bufsz;
ifc.ifc_buf = (char *) buf;
if (ioctl(sd, SIOCGIFCONF, &ifc) < 0) {
fatal("Failed to determine your configured interfaces!\n");
}
- ifr = (struct ifreq *) buf;
+ ifr = buf;
if (ifc.ifc_len == 0)
fatal("getinterfaces: SIOCGIFCONF claims you have no network interfaces!\n");
#if HAVE_SOCKADDR_SA_LEN
@@ -2219,7 +2219,7 @@
printf("Size of struct ifreq: %d\n", sizeof(struct ifreq));
#endif
- for(; ifr && *((u8 *)ifr) && ((u8 *)ifr) < buf + ifc.ifc_len;
+ for(; ifr && *((u8 *)ifr) && ((u8 *)ifr) < ((u8 *)ifr) + ifc.ifc_len;
((*(char **)&ifr) += len )) {
#if TCPIP_DEBUGGING
printf("ifr_name size = %d\n", sizeof(ifr->ifr_name));
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev
Current thread:
- gcc-4 troubleshooting Aaron J. Bedra (Aug 26)
- Re: gcc-4 troubleshooting Fyodor (Aug 26)
- Re: gcc-4 troubleshooting Emmanuel Goldstein (Aug 27)
- Re: gcc-4 troubleshooting Greg Darke (Aug 28)
- Re: gcc-4 troubleshooting Fyodor (Aug 28)
- Re: gcc-4 troubleshooting Greg Darke (Aug 28)
- Re: gcc-4 troubleshooting Duilio J. Protti (Aug 28)
- Re: gcc-4 troubleshooting Arturo 'Buanzo' Busleiman (Aug 28)
- Re: gcc-4 troubleshooting Fyodor (Aug 29)
- Re: gcc-4 troubleshooting Duilio Protti (Aug 29)
- Re: gcc-4 troubleshooting Matthew Heine (Aug 29)
- Re: gcc-4 troubleshooting Duilio Protti (Aug 29)
- Re: gcc-4 troubleshooting Fyodor (Aug 26)
