Skip to content

Commit

Permalink
global: Avoid loops unnecessarily decreasing below zero.
Browse files Browse the repository at this point in the history
Avoids complains from clang -fsanitize=integer
  • Loading branch information
sirainen authored and GitLab committed Nov 24, 2016
1 parent 21484e1 commit a058197
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lib-mail/message-address.c
Expand Up @@ -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 != ',') {
Expand Down
3 changes: 2 additions & 1 deletion src/lib-mail/message-snippet.c
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/sha3.c
Expand Up @@ -144,19 +144,23 @@ 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;
}

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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a058197

Please sign in to comment.