Date: Fri, 12 Jun 2009 09:47:22 GMT From: brian@FreeBSD.org To: henning.petersen@t-online.de, brian@FreeBSD.org, freebsd-bugs@FreeBSD.org Subject: Re: bin/135494: Use of sizeof in dhclinet.c. Message-ID: <200906120947.n5C9lMlQ065650@freefall.freebsd.org>
index | next in thread | raw e-mail
Synopsis: Use of sizeof in dhclinet.c.
State-Changed-From-To: open->closed
State-Changed-By: brian
State-Changed-When: Fri Jun 12 09:43:16 UTC 2009
State-Changed-Why:
The suggested patch is not correct. The options variable
is an array of 256 tree_cache pointers and the code wants to
set all pointers to NULL. The proposed change would just
set the first pointer to NULL.
To demonstrate:
#include <stdio.h>
#include <string.h>
struct tree_cache {
int x;
int y;
};
int
main()
{
struct tree_cache *options[256];
int f;
for (f = 0; f < 256; f++)
options[f] = (struct tree_cache *)123;
printf("Zeroing %u bytes\n", sizeof options);
memset(options, 0, sizeof options);
for (f = 0; f < 256; f++)
if (options[f] != NULL)
printf("Oops, %d is wrong\n", f);
return 0;
}
http://www.freebsd.org/cgi/query-pr.cgi?pr=135494
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906120947.n5C9lMlQ065650>
