diff options
author | Mattias Andrée <maandree@kth.se> | 2021-12-24 11:28:26 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-12-24 11:28:26 +0100 |
commit | a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563 (patch) | |
tree | b32454da6bdc383de6bf347bbe76fe9d3c7a1a8d /libkeccak_state_copy.c | |
parent | Fix marshal and unmarshal (diff) | |
download | libkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.gz libkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.bz2 libkeccak-a8c24756c08b7f41ce757b2c7a9dc7b39b3cb563.tar.xz |
Fix libkeccak_state_copy
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libkeccak_state_copy.c | 12 |
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; } |