]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Avoid loops unnecessarily decreasing below zero.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 23:59:03 +0000 (01:59 +0200)
committerGitLab <gitlab@git.dovecot.net>
Thu, 24 Nov 2016 21:27:16 +0000 (23:27 +0200)
Avoids complains from clang -fsanitize=integer

src/lib-mail/message-address.c
src/lib-mail/message-snippet.c
src/lib/sha3.c

index 64f9da22b1e595d1df4cf727ecd33aa54026c75c..90b1175f9af3fdd0612944ba63d9925bfc81eb35 100644 (file)
@@ -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 != ',') {
index b46d2d7ff1a60089182942428dd9ae10242a2832..2f3cf427505f9cb4d58508e40e736b7272c3e862 100644 (file)
@@ -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);
index d1e298954fc963fa1c21b7872b40bf08ec3d6f25..8cf61fa18d82500a3e733746b4334d12a3e46472 100644 (file)
@@ -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);