[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openbsd-tech
Subject:    awk: xfree() macro
From:       "Michael W. Bombardieri" <mb () ii ! net>
Date:       2015-02-25 5:47:42
Message-ID: 20150225054742.GA30518 () bom ! nom ! co
[Download RAW message or body]

Hi tech,

Forwarding this in case it is considered useful.
Trying to clean up xfree() macro in awk.
Remove check for NULL before calling free().
As a side effect, we might set something to NULL which is already NULL (but I suppose that's ok).

- Michael


Index: awk.h
===================================================================
RCS file: /cvs/src/usr.bin/awk/awk.h,v
retrieving revision 1.13
diff -u -p -u -r1.13 awk.h
--- awk.h	6 Oct 2008 20:38:33 -0000	1.13
+++ awk.h	25 Feb 2015 05:29:37 -0000
@@ -31,7 +31,11 @@ typedef double	Awkfloat;
 
 typedef	unsigned char uschar;
 
-#define	xfree(a)	{ if ((a) != NULL) { free((void *) (a)); (a) = NULL; } }
+#define	xfree(a)   \
+do {                      \
+	free((void *)(a)); \
+	(a) = NULL;        \
+} while (0)
 
 #define	NN(p)	((p) ? (p) : "(null)")	/* guaranteed non-null for dprintf 
 */

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic