bin/135494: Use of sizeof in dhclinet.c.

brian at FreeBSD.org brian at FreeBSD.org
Fri Jun 12 09:47:23 UTC 2009


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


More information about the freebsd-bugs mailing list