From: Aki Tuomi Date: Mon, 19 Oct 2020 10:49:29 +0000 (+0300) Subject: global: Explicitly wrap values to fit target X-Git-Tag: 2.3.13~74 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb6aa64435e0ffd66b81cd4895127187f28fa20b;p=thirdparty%2Fdovecot%2Fcore.git global: Explicitly wrap values to fit target --- diff --git a/src/lib-compression/test-compression.c b/src/lib-compression/test-compression.c index 2f5cf283da..1bf97c48c9 100644 --- a/src/lib-compression/test-compression.c +++ b/src/lib-compression/test-compression.c @@ -275,7 +275,7 @@ static void test_compression_handler(const struct compression_handler *handler) if (i_rand_limit(3) == 0) buf[i] = i_rand_limit(4); else - buf[i] = i; + buf[i] = i % UCHAR_MAX; } for (i = 0; i < 1024*128 / sizeof(buf); i++) { sha1_loop(&sha1, buf, sizeof(buf)); diff --git a/src/lib-imap/imap-utf7.c b/src/lib-imap/imap-utf7.c index 6fe603bf5f..90abbc829f 100644 --- a/src/lib-imap/imap-utf7.c +++ b/src/lib-imap/imap-utf7.c @@ -214,7 +214,7 @@ static int mbase64_decode_to_utf8(string_t *dest, const char **_src) break; } - output[outpos % 4] = (input[1] << 4) | (input[2] >> 2); + output[outpos % 4] = ((input[1] << 4) & 0xff) | (input[2] >> 2); if (++outpos % 4 == outstart) { if (utf16buf_to_utf8(dest, output, &outstart, 4) < 0) return -1; diff --git a/src/lib/base64.c b/src/lib/base64.c index 7d41638313..3c7117db85 100644 --- a/src/lib/base64.c +++ b/src/lib/base64.c @@ -692,7 +692,7 @@ int base64_decode_more(struct base64_decoder *dec, dec->sub_pos++; break; case 2: - dec->buf = (dec->buf << 4) | (dm >> 2); + dec->buf = ((dec->buf << 4) & 0xff) | (dm >> 2); buffer_append_c(dest, dec->buf); dst_avail--; dec->buf = dm; diff --git a/src/lib/test-array.c b/src/lib/test-array.c index 75739114b4..1799487ddd 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -204,7 +204,8 @@ static void test_array_cmp(void) unsigned int j = i_rand_limit(NELEMS); const unsigned short *ptmp = array_idx(&arr2, j); unsigned short tmp = *ptmp; - unsigned short repl = tmp + deltas[i_rand_limit(N_ELEMENTS(deltas))]; + unsigned short repl = ((unsigned int)tmp + + deltas[i_rand_limit(N_ELEMENTS(deltas))]) & 0xffff; array_idx_set(&arr2, j, &repl); test_assert_idx(array_cmp(&arr1, &arr2) == (tmp == repl), i); diff --git a/src/lib/test-data-stack.c b/src/lib/test-data-stack.c index a5551e0acd..35c9e81de6 100644 --- a/src/lib/test-data-stack.c +++ b/src/lib/test-data-stack.c @@ -21,7 +21,7 @@ static void test_ds_buffers(void) /* grow it */ unsigned char *p2 = t_buffer_get(i); test_assert_idx(p == p2, i); - p[i-1] = i; + p[i-1] = i & 0xff; test_assert_idx(p[i-2] == (unsigned char)(i-1), i); } /* now fix it permanently */ @@ -79,7 +79,7 @@ static void test_ds_realloc() for (i = 2; i <= left; i++) { /* grow it */ test_assert_idx(t_try_realloc(p, i), i); - p[i-1] = i; + p[i-1] = i & 0xff; test_assert_idx(p[i-2] == (unsigned char)(i-1), i); } test_assert(t_get_bytes_available() < 64 + MEM_ALIGN(1)); diff --git a/src/lib/test-istream-concat.c b/src/lib/test-istream-concat.c index 7f0006af22..fd3887ddaf 100644 --- a/src/lib/test-istream-concat.c +++ b/src/lib/test-istream-concat.c @@ -69,7 +69,7 @@ static bool test_istream_concat_random(void) data_len = i_rand_minmax(1, TEST_MAX_ISTREAM_SIZE); w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) - w_data[j] = offset++; + w_data[j] = (offset++) & 0xff; streams[i] = test_istream_create_data(w_data, data_len); test_istream_set_allow_eof(streams[i], TRUE); } diff --git a/src/lib/test-istream-seekable.c b/src/lib/test-istream-seekable.c index 594e0321a6..e57eebadfb 100644 --- a/src/lib/test-istream-seekable.c +++ b/src/lib/test-istream-seekable.c @@ -85,7 +85,7 @@ static void test_istream_seekable_random(void) data_len = i_rand_minmax(1, 100); w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) - w_data[j] = offset++; + w_data[j] = (offset++) & 0xff; streams[i] = test_istream_create_data(w_data, data_len); streams[i]->seekable = FALSE; test_istream_set_allow_eof(streams[i], TRUE);