diff options
author | Andre Heinecke <[email protected]> | 2018-08-08 12:25:28 +0000 |
---|---|---|
committer | Andre Heinecke <[email protected]> | 2018-08-08 12:25:28 +0000 |
commit | fdc07b3ddc2f68e6fcb33703ea41126d0a841290 (patch) | |
tree | 9063ea454950ec79c8314a6def9a10307e8dab3b /src/gpgme-json.c | |
parent | json: Add checks when skipping byte (diff) | |
download | gpgme-fdc07b3ddc2f68e6fcb33703ea41126d0a841290.tar.gz gpgme-fdc07b3ddc2f68e6fcb33703ea41126d0a841290.zip |
json: Only use calloc instead of malloc
* src/cJSON.c, src/gpgme-json.c (CALLOC_ONLY): New define
to change xmalloc / xtrymalloc to use calloc.
--
Some people consider malloc dangerous as it might allow an
information leak.
Diffstat (limited to 'src/gpgme-json.c')
-rw-r--r-- | src/gpgme-json.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/gpgme-json.c b/src/gpgme-json.c index 9cae944c..5a9b9cf7 100644 --- a/src/gpgme-json.c +++ b/src/gpgme-json.c @@ -87,13 +87,7 @@ static struct * Helper functions and macros */ -#define xtrymalloc(a) gpgrt_malloc ((a)) #define xtrystrdup(a) gpgrt_strdup ((a)) -#define xmalloc(a) ({ \ - void *_r = gpgrt_malloc ((a)); \ - if (!_r) \ - xoutofcore ("malloc"); \ - _r; }) #define xcalloc(a,b) ({ \ void *_r = gpgrt_calloc ((a), (b)); \ if (!_r) \ @@ -111,6 +105,21 @@ static struct _r; }) #define xfree(a) gpgrt_free ((a)) +/* Only use calloc. */ +#define CALLOC_ONLY 1 + +#if CALLOC_ONLY +#define xtrymalloc(a) gpgrt_calloc (1, (a)) +#define xmalloc(a) xcalloc(1, (a)) +#else +#define xtrymalloc(a) gpgrt_malloc ((a)) +#define xmalloc(a) ({ \ + void *_r = gpgrt_malloc ((a)); \ + if (!_r) \ + xoutofcore ("malloc"); \ + _r; }) +#endif + #define spacep(p) (*(p) == ' ' || *(p) == '\t') #ifndef HAVE_STPCPY |