aboutsummaryrefslogtreecommitdiffstats
path: root/unmarshal.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-05-17 21:02:39 +0200
committerMattias Andrée <m@maandree.se>2026-05-17 21:02:39 +0200
commit5fb2a5fe67521a452463e6b91cee406ec14c35a0 (patch)
treef6be3a0c9086ef7122a7d5789818bdc7c0bb1081 /unmarshal.c
parentUpdate year (diff)
downloadlibsha2-b5a4c67f7b6cb0ba294eafcba7ae4e3cb91f60dd.tar.gz
libsha2-b5a4c67f7b6cb0ba294eafcba7ae4e3cb91f60dd.tar.bz2
libsha2-b5a4c67f7b6cb0ba294eafcba7ae4e3cb91f60dd.tar.xz
Fix mistakesHEAD1.1.5master
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'unmarshal.c')
-rw-r--r--unmarshal.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/unmarshal.c b/unmarshal.c
index 8c5780d..0bfecfd 100644
--- a/unmarshal.c
+++ b/unmarshal.c
@@ -5,7 +5,7 @@
size_t
libsha2_unmarshal(struct libsha2_state *restrict state, const void *restrict buf_, size_t bufsize)
{
- const char *restrict buf = buf_;
+ const unsigned char *restrict buf = buf_;
size_t off = 0;
int version;
@@ -14,16 +14,16 @@ libsha2_unmarshal(struct libsha2_state *restrict state, const void *restrict buf
return 0;
}
- version = *(const int *)buf;
- if (version < 0 || version > 1) { /* version */
+ memcpy(&version, buf, sizeof(int));
+ if (version < 0 || version > 1) {
errno = EINVAL;
return 0;
}
off += sizeof(int);
- state->algorithm = *(const enum libsha2_algorithm *)&buf[off];
+ memcpy(&state->algorithm, &buf[off], sizeof(enum libsha2_algorithm));
off += sizeof(enum libsha2_algorithm);
- state->message_size = *(const size_t *)&buf[off];
+ memcpy(&state->message_size, &buf[off], sizeof(size_t));
off += sizeof(size_t);
switch (state->algorithm) {
@@ -68,7 +68,7 @@ libsha2_unmarshal(struct libsha2_state *restrict state, const void *restrict buf
errno = EINVAL;
return 0;
}
- state->chunk_size = *(const size_t *)&buf[off];
+ memcpy(&state->chunk_size, &buf[off], sizeof(size_t));
off += sizeof(size_t);
if (bufsize - off < (state->message_size / 8) % state->chunk_size) {