]> 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)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 25 Nov 2016 13:28:46 +0000 (15:28 +0200)
Avoids complains from clang -fsanitize=integer

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

index 36cb4832667c013479c656d548ca4c3e134e2a03..4f1a31f1e77c19880def8e2d215c13dcaf21eb02 100644 (file)
@@ -281,7 +281,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 09c393c04b9940822971f2caaee14cf813581035..bb1dba4ceaab0e1bcaaf1c5cd612dfd0561e2b5d 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);