[PATCH] README.Coding: initialize pointers
Ralph Boehme
rb at sernet.de
Tue Oct 20 10:15:13 UTC 2015
Hi!
What about actually adding the requirement of initializing pointers to
NULL to README.Coding ?
-Ralph
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de,mailto:kontakt@sernet.de
-------------- next part --------------
From b6581eb6ce2769d1933df48a2274a99f53a25ca4 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Tue, 20 Oct 2015 12:01:22 +0200
Subject: [PATCH] README.Coding: initialize pointers
Pointers must be initialized to NULL.
Signed-off-by: Ralph Boehme <slow at samba.org>
---
README.Coding | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/README.Coding b/README.Coding
index 52dca49..d6fd9b1 100644
--- a/README.Coding
+++ b/README.Coding
@@ -320,6 +320,25 @@ Samba tries to avoid "typedef struct { .. } x_t;" so we do always try to use
"struct x { .. };". We know there are still such typedefs in the code,
but for new code, please don't do that anymore.
+Initialize pointers
+-------------------
+
+All pointer variables MUST be initialized to NULL. History has
+demonstrated that uninitialized pointer variables have lead to various
+bugs and security issues.
+
+Good Example:
+
+ char *pointer = NULL;
+
+ pointer = some_func();
+
+Bad Example:
+
+ char *pointer;
+
+ pointer = some_func();
+
Make use of helper variables
----------------------------
@@ -329,7 +348,7 @@ it's also easier to use the "step" command within gdb.
Good Example:
- char *name;
+ char *name = NULL;
name = get_some_name();
if (name == NULL) {
--
2.1.0
More information about the samba-technical
mailing list