summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpi/mpiutil.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index a5583c79..74fbac37 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -366,10 +366,13 @@ _gcry_mpi_copy (gcry_mpi_t a)
gcry_mpi_t b;
if( a && (a->flags & 4) ) {
- void *p = _gcry_is_secure(a->d)? xmalloc_secure ((a->sign+7)/8)
- : xmalloc ((a->sign+7)/8);
- if (a->d)
- memcpy( p, a->d, (a->sign+7)/8 );
+ void *p = NULL;
+ if (a->sign) {
+ p = _gcry_is_secure(a->d)? xmalloc_secure ((a->sign+7)/8)
+ : xmalloc ((a->sign+7)/8);
+ if (a->d)
+ memcpy( p, a->d, (a->sign+7)/8 );
+ }
b = mpi_set_opaque( NULL, p, a->sign );
b->flags = a->flags;
b->flags &= ~(16|32); /* Reset the immutable and constant flags. */