Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Wrap complex macros in do { ... } while (0). A...



details:   https://anonhg.NetBSD.org/src/rev/f9b89bc9ef14
branches:  trunk
changeset: 329873:f9b89bc9ef14
user:      apb <apb%NetBSD.org@localhost>
date:      Thu Jun 12 19:05:37 2014 +0000

description:
Wrap complex macros in do { ... } while (0).  Also replace the magic
number 1600000 with a macro.

diffstat:

 lib/libc/gen/arc4random.c |  18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diffs (53 lines):

diff -r 94acc33352cd -r f9b89bc9ef14 lib/libc/gen/arc4random.c
--- a/lib/libc/gen/arc4random.c Thu Jun 12 19:02:35 2014 +0000
+++ b/lib/libc/gen/arc4random.c Thu Jun 12 19:05:37 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arc4random.c,v 1.22 2014/06/07 20:55:47 roy Exp $      */
+/*     $NetBSD: arc4random.c,v 1.23 2014/06/12 19:05:37 apb Exp $      */
 /*     $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
 
 /*
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: arc4random.c,v 1.22 2014/06/07 20:55:47 roy Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.23 2014/06/12 19:05:37 apb Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -50,6 +50,8 @@
 __weak_alias(arc4random_uniform,_arc4random_uniform)
 #endif
 
+#define REKEY_BYTES    1600000
+
 struct arc4_stream {
        bool inited;
        uint8_t i;
@@ -60,8 +62,12 @@
 };
 
 #ifdef _REENTRANT
-#define LOCK(rs)       if (__isthreaded) mutex_lock(&(rs)->mtx);
-#define UNLOCK(rs)     if (__isthreaded) mutex_unlock(&(rs)->mtx);
+#define LOCK(rs)       do { \
+                               if (__isthreaded) mutex_lock(&(rs)->mtx);
+                       } while (/*CONSTCOND*/ 0)
+#define UNLOCK(rs)     do { \
+                               if (__isthreaded) mutex_unlock(&(rs)->mtx); \
+                       } while (/*CONSTCOND*/ 0)
 #else
 #define LOCK(rs)
 #define UNLOCK(rs)
@@ -177,8 +183,8 @@
        for (j = 0; j < __arraycount(as->s) * sizeof(uint32_t); j++)
                arc4_getbyte(as);
 
-       /* Stir again after swallowing 1600000 bytes or if the pid changes */
-       as->count = 1600000;
+       /* Stir again after REKEY_BYTES bytes, or if the pid changes */
+       as->count = REKEY_BYTES;
 }
 
 static inline void



Home | Main Index | Thread Index | Old Index