[PATCH] libwbclient clear pointer on bad read
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Jan 19 02:50:24 MST 2015
On Sun, Jan 18, 2015 at 05:23:43PM +0000, Matthew Newton wrote:
> Hi,
>
> On Sun, Jan 18, 2015 at 04:26:41PM +0100, Stefan (metze) Metzmacher wrote:
> > Am 17.01.2015 um 02:44 schrieb Matthew Newton:
> > > + if ((fd_info = winbindd_fd_info()) == NULL) {
> > > + return;
> > > + }
> >
> > Can you please change all changes like this into two lines:
> >
> > fd_info = winbindd_fd_info();
> > if (fd_info == NULL) {
> > ...
>
> No probs - I'll send updated patches.
>
> Could you update README.Coding? It says both forms are acceptable
> so I guess maybe it's out of date.
Something like the attached patch?
Review appreciated! :-)
Thanks,
Volker
--
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 at sernet.de
-------------- next part --------------
From 3b648e1c308e93f10a0164b7da49dc96ab47dc84 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 19 Jan 2015 10:48:20 +0100
Subject: [PATCH] README.Coding: Add hint for if-statments
Signed-off-by: Volker Lendecke <vl at samba.org>
---
README.Coding | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/README.Coding b/README.Coding
index 0bbba9f..f19399e 100644
--- a/README.Coding
+++ b/README.Coding
@@ -298,25 +298,6 @@ Good Examples:
}
-Checking Pointer Values
------------------------
-
-When invoking functions that return pointer values, either of the following
-are acceptable. Use your best judgement and choose the more readable option.
-Remember that many other persons will review it:
-
- if ((x = malloc(sizeof(short)*10)) == NULL ) {
- fprintf(stderr, "Unable to alloc memory!\n");
- }
-
-or:
-
- x = malloc(sizeof(short)*10);
- if (!x) {
- fprintf(stderr, "Unable to alloc memory!\n");
- }
-
-
Primitive Data Types
--------------------
@@ -364,6 +345,33 @@ Bad Example:
ret = some_function_my_name(get_some_name());
...
+Please try to avoid passing function return values to if- or
+while-conditions. The reason for this is better handling of code under a
+debugger.
+
+Good example:
+
+ x = malloc(sizeof(short)*10);
+ if (!x) {
+ fprintf(stderr, "Unable to alloc memory!\n");
+ }
+
+Bad example:
+
+ if ((x = malloc(sizeof(short)*10)) == NULL ) {
+ fprintf(stderr, "Unable to alloc memory!\n");
+ }
+
+There are exceptions to this rule. One example is walking a data structure in
+an iterator style:
+
+ while ((opt = poptGetNextOpt(pc)) != -1) {
+ ... do something with opt ...
+ }
+
+But in general, please try to avoid this pattern.
+
+
Control-Flow changing macros
----------------------------
--
1.9.1
More information about the samba-technical
mailing list