From a05819736f348d0c5ac8b4966ac6b04c21e1a391 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 19 Nov 2016 01:59:03 +0200 Subject: [PATCH] global: Avoid loops unnecessarily decreasing below zero. Avoids complains from clang -fsanitize=integer --- src/lib-mail/message-address.c | 3 ++- src/lib-mail/message-snippet.c | 3 ++- src/lib/sha3.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib-mail/message-address.c b/src/lib-mail/message-address.c index 64f9da22b1..90b1175f9a 100644 --- a/src/lib-mail/message-address.c +++ b/src/lib-mail/message-address.c @@ -337,7 +337,8 @@ static int parse_address_list(struct message_address_parser_context *ctx, int ret = 0; /* address-list = (address *("," address)) / obs-addr-list */ - while (max_addresses-- > 0) { + while (max_addresses > 0) { + max_addresses--; if ((ret = parse_address(ctx)) == 0) break; if (*ctx->parser.data != ',') { diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index b46d2d7ff1..2f3cf42750 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -75,8 +75,9 @@ static bool snippet_generate(struct snippet_context *ctx, if (ctx->chars_left-- == 0) return FALSE; } - if (ctx->chars_left-- == 0) + if (ctx->chars_left == 0) return FALSE; + ctx->chars_left--; count = uni_utf8_char_bytes(data[i]); i_assert(i + count <= size); str_append_n(ctx->snippet, data + i, count); diff --git a/src/lib/sha3.c b/src/lib/sha3.c index d1e298954f..8cf61fa18d 100644 --- a/src/lib/sha3.c +++ b/src/lib/sha3.c @@ -144,9 +144,11 @@ void sha3_loop(void *context, const void *data, size_t len) if(len < old_tail) { /* have no complete word or haven't started * the word yet */ /* endian-independent code follows: */ - while (len-- > 0) + while (len > 0) { + len--; ctx->saved |= (uint64_t) (*(buf++)) << ((ctx->byteIndex++) * 8); + } i_assert(ctx->byteIndex < 8); return; } @@ -154,9 +156,11 @@ void sha3_loop(void *context, const void *data, size_t len) if(old_tail != 0) { /* will have one word to process */ /* endian-independent code follows: */ len -= old_tail; - while (old_tail-- > 0) + while (old_tail > 0) { + old_tail--; ctx->saved |= (uint64_t) (*(buf++)) << ((ctx->byteIndex++) * 8); + } /* now ready to add saved to the sponge */ ctx->s[ctx->wordIndex] ^= ctx->saved; @@ -200,7 +204,8 @@ void sha3_loop(void *context, const void *data, size_t len) /* finally, save the partial word */ i_assert(ctx->byteIndex == 0 && tail < 8); - while (tail-- > 0) { + while (tail > 0) { + tail--; ctx->saved |= (uint64_t) (*(buf++)) << ((ctx->byteIndex++) * 8); } i_assert(ctx->byteIndex < 8);