Module Name: src
Committed By: christos
Date: Sat Apr 24 00:54:07 UTC 2010
Modified Files:
src/share/misc: style
Log Message:
Be explicit about sizeof(*var) being preferred over sizeof(type).
To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/share/misc/style
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/share/misc/style
diff -u src/share/misc/style:1.45 src/share/misc/style:1.46
--- src/share/misc/style:1.45 Sun Feb 15 02:01:41 2009
+++ src/share/misc/style Fri Apr 23 20:54:07 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: style,v 1.45 2009/02/15 07:01:41 dholland Exp $ */
+/* $NetBSD: style,v 1.46 2010/04/24 00:54:07 christos Exp $ */
/*
* The revision control tag appears first, with a blank line after it.
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: style,v 1.45 2009/02/15 07:01:41 dholland Exp $");
+__RCSID("$NetBSD: style,v 1.46 2010/04/24 00:54:07 christos Exp $");
/*
* VERY important single-line comments look like this.
@@ -361,9 +361,12 @@
* Routines returning ``void *'' should not have their return
* values cast to more specific pointer types.
*
+ * Prefer sizeof(*var) over sizeof(type) because if type changes,
+ * the change needs to be done in one place.
+ *
* Use err/warn(3), don't roll your own!
*/
- if ((four = malloc(sizeof(struct foo))) == NULL)
+ if ((four = malloc(sizeof(*four))) == NULL)
err(1, NULL);
if ((six = (int *)overflow()) == NULL)
errx(1, "Number overflowed.");