aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-12-24 11:28:26 +0100
committerMattias Andrée <maandree@kth.se>2021-12-24 11:28:26 +0100
commita8c24756c08b7f41ce757b2c7a9dc7b39b3cb563 (patch)
treeb32454da6bdc383de6bf347bbe76fe9d3c7a1a8d
parentFix marshal and unmarshal (diff)
downloadlibkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.gz
libkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.bz2
libkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.xz
Fix libkeccak_state_copy
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libkeccak_state_copy.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libkeccak_state_copy.c b/libkeccak_state_copy.c
index 97a76ef..bf82fa9 100644
--- a/libkeccak_state_copy.c
+++ b/libkeccak_state_copy.c
@@ -13,9 +13,13 @@ int
libkeccak_state_copy(struct libkeccak_state *restrict dest, const struct libkeccak_state *restrict src)
{
memcpy(dest, src, sizeof(struct libkeccak_state));
- dest->M = malloc(src->mlen * sizeof(char));
- if (!dest->M)
- return -1;
- memcpy(dest->M, src->M, src->mptr * sizeof(char));
+ if (src->mlen) {
+ dest->M = malloc(src->mlen * sizeof(char));
+ if (!dest->M)
+ return -1;
+ memcpy(dest->M, src->M, src->mptr * sizeof(char));
+ } else {
+ dest->M = NULL;
+ }
return 0;
}