novice coding in /linux/net/ipv4/util.c From: DJ Barrow <dj.barrow@asitatech.com>

DJ Barrow (dj.barrow@asitatech.com)
Mon, 22 Apr 2002 16:12:16 +0100


Hi ,
While debugging last night with Brian O'Sullivan I found this beauty.

char *in_ntoa(__u32 in)
{
static char buff[18];
char *p;

p = (char *) &in;
sprintf(buff, "%d.%d.%d.%d",
(p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
return(buff);
}

This textbook peice of novice coding which has existed since 2.2.14.
For those who can't spot the error, please note that this function is
returning a static string, excellent stuff if you are hoping to reuse the
same function like the following
printk("%s %s\n",in_ntoa(addr1),in_ntoa(addr2));
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/