Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/share/misc Be explicit about sizeof(*var) being preferred ov...
details: https://anonhg.NetBSD.org/src/rev/be45ef1e1a51
branches: trunk
changeset: 754226:be45ef1e1a51
user: christos <christos%NetBSD.org@localhost>
date: Sat Apr 24 00:54:07 2010 +0000
description:
Be explicit about sizeof(*var) being preferred over sizeof(type).
diffstat:
share/misc/style | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diffs (32 lines):
diff -r 162e4af4a014 -r be45ef1e1a51 share/misc/style
--- a/share/misc/style Sat Apr 24 00:38:30 2010 +0000
+++ b/share/misc/style Sat Apr 24 00:54:07 2010 +0000
@@ -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.");
Home |
Main Index |
Thread Index |
Old Index