aboutsummaryrefslogtreecommitdiffstats
path: root/common/xmalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/xmalloc.c')
-rw-r--r--common/xmalloc.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/common/xmalloc.c b/common/xmalloc.c
index 999ec00f8..3378e487b 100644
--- a/common/xmalloc.c
+++ b/common/xmalloc.c
@@ -47,7 +47,15 @@ out_of_core(void)
void *
xmalloc( size_t n )
{
- void *p = malloc( n );
+ void *p;
+
+ /* Make sure that xmalloc (0) works. This is the same behaviour
+ has in gpg 2.x. Note that in contrast to this code, Libgcrypt
+ (and thus most xmallocs in gpg 2.x) detect the !n and bail out. */
+ if (!n)
+ n = 1;
+
+ p = malloc( n );
if( !p )
out_of_core();
return p;
@@ -65,7 +73,14 @@ xrealloc( void *a, size_t n )
void *
xcalloc( size_t n, size_t m )
{
- void *p = calloc( n, m );
+ void *p;
+
+ if (!n)
+ n = 1;
+ if (!m)
+ m = 1;
+
+ p = calloc( n, m );
if( !p )
out_of_core();
return p;