From ae42e15f211feb8625450e5dcc899ae29d885ba7 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 9 Feb 2019 21:30:06 +0100 Subject: Fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- digest.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'digest.c') diff --git a/digest.c b/digest.c index 8658388..bcd318f 100644 --- a/digest.c +++ b/digest.c @@ -16,10 +16,10 @@ libsha2_digest(struct libsha2_state *restrict state, const char *restrict messag char *appendix; size_t i, j, k, n; - if (msglen & ~7) { - libsha2_update(state, message, msglen & ~7); - message += msglen & ~7; - msglen &= 7; + if (msglen & ~(size_t)7) { + libsha2_update(state, message, msglen & ~(size_t)7); + message += msglen & ~(size_t)7; + msglen &= (size_t)7; } k = 8 * state->chunk_size; @@ -31,36 +31,31 @@ libsha2_digest(struct libsha2_state *restrict state, const char *restrict messag if (msglen) { j = 7 - msglen; *appendix = *message; - *appendix |= 1 << j; - *appendix &= ~((1 << j) - 1); + *appendix |= (char)(1 << j); + *appendix &= (char)~((1 << j) - 1); } else { - *appendix = (unsigned char)128; + *appendix = (char)128; } k = state->message_size + msglen; i = state->chunk_size / 8; appendix += n + i - 1; for (i = i < sizeof(size_t) ? i : sizeof(size_t); i--;) - *(appendix - i) = (unsigned char)((k >> (i * 8)) & 255); + *(appendix - i) = (char)((k >> (i * 8)) & 255); n += state->chunk_size; libsha2_update(state, state->appendix, n); n = libsha2_algorithm_output_size(state->algorithm); - switch (state->algorithm) { - case LIBSHA2_224: - case LIBSHA2_256: + if (state->algorithm <= LIBSHA2_256) { for (i = 0; i < 8; i++) for (j = 0; j < (state->chunk_size / 16); j++) if (k = (i + 1) * (state->chunk_size / 16) - j - 1, k < n) output[k] = (char)((state->h.b32[i] >> (8 * j)) & 255); - break; - - default: + } else { for (i = 0; i < 8; i++) for (j = 0; j < (state->chunk_size / 16); j++) if (k = (i + 1) * (state->chunk_size / 16) - j - 1, k < n) output[k] = (char)((state->h.b64[i] >> (8 * j)) & 255); - break; } } -- cgit v1.2.3-70-g09d2