aboutsummaryrefslogtreecommitdiffstats
path: root/libkeccak_state_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'libkeccak_state_copy.c')
-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;
}