summaryrefslogtreecommitdiff
path: root/src/cJSON.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cJSON.c')
-rw-r--r--src/cJSON.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/cJSON.c b/src/cJSON.c
index 7769b0e..1925a04 100644
--- a/src/cJSON.c
+++ b/src/cJSON.c
@@ -50,21 +50,13 @@
#include "cJSON.h"
+
/* Only use calloc. */
#define CALLOC_ONLY 1
/* Maximum recursion depth */
#define MAX_DEPTH 512
-/* To avoid that a compiler optimizes certain memset calls away, these
- macros may be used instead. */
-#define wipememory2(_ptr,_set,_len) do { \
- volatile char *_vptr=(volatile char *)(_ptr); \
- size_t _vlen=(_len); \
- while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
- } while(0)
-#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
-
/* We use malloc function wrappers from gpgrt (aka libgpg-error). */
#include <gpgrt.h>
#define xtrycalloc(a,b) gpgrt_calloc ((a), (b))
@@ -77,6 +69,16 @@
#endif
+static void
+wipememory (void *ptr, size_t len)
+{
+ /* Prevent compiler from optimizing away the call to memset by accessing
+ * memset through volatile pointer. */
+ static void *(*volatile memset_ptr)(void *, int, size_t) = (void *)memset;
+ memset_ptr (ptr, 0, len);
+}
+
+
static int
cJSON_strcasecmp (const char *s1, const char *s2)
{