From: Aki Tuomi Date: Wed, 23 Aug 2017 09:59:42 +0000 (+0300) Subject: global: Replace rand with i_rand X-Git-Tag: 2.3.0.rc1~1080 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=62461eb609e1d852e027cf4e07d30d51288678a2;p=thirdparty%2Fdovecot%2Fcore.git global: Replace rand with i_rand --- diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c index dc1aff94c2..3f9cde19c3 100644 --- a/src/auth/auth-request.c +++ b/src/auth/auth-request.c @@ -1924,7 +1924,7 @@ void auth_request_set_field(struct auth_request *request, "Invalid delay_until randomness number '%s'", p); request->failed = TRUE; } else { - extra_secs = rand() % extra_secs; + extra_secs = i_rand() % extra_secs; } } if (str_to_time(value, ×tamp) < 0) { diff --git a/src/director/director-test.c b/src/director/director-test.c index bf1c427dd1..af0ba4830b 100644 --- a/src/director/director-test.c +++ b/src/director/director-test.c @@ -302,9 +302,9 @@ director_connection_input(struct director_connection *conn, o_stream_nsend(output, data, size); i_stream_skip(input, size); - if (rand() % 3 == 0 && conn->to_delay == NULL) { + if (i_rand() % 3 == 0 && conn->to_delay == NULL) { conn->to_delay = - timeout_add(rand() % DIRECTOR_CONN_MAX_DELAY_MSECS, + timeout_add(i_rand() % DIRECTOR_CONN_MAX_DELAY_MSECS, director_connection_timeout, conn); io_remove(&conn->in_io); io_remove(&conn->out_io); @@ -435,9 +435,9 @@ static void admin_random_action(struct admin_connection *conn) return; hosts = array_get(&hosts_array, &count); - i = rand() % count; + i = i_rand() % count; - hosts[i]->vhost_count = (rand() % 20) * 10; + hosts[i]->vhost_count = (i_rand() % 20) * 10; admin_send(conn, t_strdup_printf("HOST-SET\t%s\t%u\n", net_ip2addr(&hosts[i]->ip), hosts[i]->vhost_count)); @@ -525,7 +525,7 @@ director_connection_disconnect_timeout(void *context ATTR_UNUSED) count++; if (count != 0) { - i = 0; count = rand() % count; + i = 0; count = i_rand() % count; for (conn = director_connections; i < count; conn = conn->next) { i_assert(conn != NULL); i++; @@ -546,7 +546,7 @@ static void main_init(const char *admin_path) admin_read_hosts(admin); to_disconnect = - timeout_add(1000*(5 + rand()%DIRECTOR_DISCONNECT_TIMEOUT_SECS), + timeout_add(1000*(5 + i_rand()%DIRECTOR_DISCONNECT_TIMEOUT_SECS), director_connection_disconnect_timeout, (void *)NULL); } diff --git a/src/director/test-user-directory.c b/src/director/test-user-directory.c index ad4c695348..2c62992b20 100644 --- a/src/director/test-user-directory.c +++ b/src/director/test-user-directory.c @@ -78,15 +78,15 @@ static void test_user_directory_random(void) struct user_directory *dir; struct mail_host *host = t_new(struct mail_host, 1); time_t timestamp; - unsigned int i, count = 10000 + rand()%10000; + unsigned int i, count = 10000 + i_rand()%10000; test_begin("user directory random"); dir = user_directory_init(USER_DIR_TIMEOUT, NULL); for (i = 0; i < count; i++) { - if (rand() % 10 == 0) + if (i_rand() % 10 == 0) timestamp = ioloop_time; else - timestamp = ioloop_time-rand()%100; + timestamp = ioloop_time-i_rand()%100; (void)user_directory_add(dir, i+1, host, timestamp); } verify_user_directory(dir, count); diff --git a/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c b/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c index f9da9693cf..50f3f70d31 100644 --- a/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c +++ b/src/doveadm/dsync/test-dsync-mailbox-tree-sync.c @@ -48,7 +48,7 @@ static struct dsync_mailbox_node * random_node_create(struct dsync_mailbox_tree *tree, unsigned int counter, const char *name) { - return node_create(tree, counter, name, rand() % 10); + return node_create(tree, counter, name, i_rand() % 10); } static void nodes_create(struct dsync_mailbox_tree *tree, unsigned int *counter, @@ -76,7 +76,7 @@ static void create_random_nodes(struct dsync_mailbox_tree *tree, const char *parent_name, unsigned int depth, unsigned int *counter) { - unsigned int parent_len, i, nodes_count = 1 + rand() % 3; + unsigned int parent_len, i, nodes_count = 1 + i_rand() % 3; string_t *str; if (depth == MAX_DEPTH) diff --git a/src/lib-compression/test-compression.c b/src/lib-compression/test-compression.c index 7779e5605c..9a4702efce 100644 --- a/src/lib-compression/test-compression.c +++ b/src/lib-compression/test-compression.c @@ -52,8 +52,8 @@ static void test_compression_handler(const struct compression_handler *handler) /* 3) write semi-compressible data */ for (i = 0; i < sizeof(buf); i++) { - if (rand () % 3 == 0) - buf[i] = rand() % 4; + if (i_rand() % 3 == 0) + buf[i] = i_rand() % 4; else buf[i] = i; } diff --git a/src/lib-dict/test-dict-client.c b/src/lib-dict/test-dict-client.c index 3ca362aaed..44561680bf 100644 --- a/src/lib-dict/test-dict-client.c +++ b/src/lib-dict/test-dict-client.c @@ -55,9 +55,9 @@ int main(int argc, char *argv[]) i_fatal("dict_init(%s) failed: %s", argv[1], error); for (i = 0;; i++) { - i_snprintf(key, sizeof(key), "%s/%02x", prefix, rand() % 0xff); - i_snprintf(value, sizeof(value), "%04x", rand() % 0xffff); - switch (rand() % 4) { + i_snprintf(key, sizeof(key), "%s/%02x", prefix, i_rand() % 0xff); + i_snprintf(value, sizeof(value), "%04x", i_rand() % 0xffff); + switch (i_rand() % 4) { case 0: pending++; dict_lookup_async(dict, key, lookup_callback, NULL); diff --git a/src/lib-fs/fs-randomfail.c b/src/lib-fs/fs-randomfail.c index 563e8603d5..37ef24b0cb 100644 --- a/src/lib-fs/fs-randomfail.c +++ b/src/lib-fs/fs-randomfail.c @@ -237,7 +237,7 @@ static bool fs_random_fail(struct fs *_fs, int divider, enum fs_op op) if (fs->op_probability[op] == 0) return FALSE; - if ((unsigned int)(rand() % (100*divider)) <= fs->op_probability[op]) { + if ((unsigned int)(i_rand() % (100*divider)) <= fs->op_probability[op]) { errno = EIO; fs_set_error(_fs, RANDOMFAIL_ERROR); return TRUE; @@ -276,7 +276,7 @@ fs_random_fail_range(struct fs *_fs, enum fs_op op, uoff_t *offset_r) if (!fs_random_fail(_fs, 1, op)) return FALSE; *offset_r = fs->range_start[op] + - rand() % (fs->range_end[op] - fs->range_start[op] + 1); + i_rand() % (fs->range_end[op] - fs->range_start[op] + 1); return TRUE; } diff --git a/src/lib-fts/test-fts-tokenizer.c b/src/lib-fts/test-fts-tokenizer.c index 5d34c0d761..56c77b2d30 100644 --- a/src/lib-fts/test-fts-tokenizer.c +++ b/src/lib-fts/test-fts-tokenizer.c @@ -113,7 +113,7 @@ test_tokenizer_inputoutput(struct fts_tokenizer *tok, const char *_input, /* test input in random chunks */ outi = first_outi; for (i = 0; i < input_len; i += char_len) { - max = rand() % (input_len - i) + 1; + max = i_rand() % (input_len - i) + 1; for (char_len = 0; char_len < max; ) char_len += uni_utf8_char_bytes(input[i+char_len]); while (fts_tokenizer_next(tok, input+i, char_len, &token, &error) > 0) { @@ -488,7 +488,7 @@ static void test_fts_tokenizer_random(void) for (i = 0; i < 10000; i++) T_BEGIN { for (unsigned int j = 0; j < sizeof(addr); j++) - addr[j] = test_chars[rand() % N_ELEMENTS(test_chars)]; + addr[j] = test_chars[i_rand() % N_ELEMENTS(test_chars)]; str_truncate(str, 0); (void)uni_utf8_get_valid_data(addr, sizeof(addr), str); while (fts_tokenizer_next(tok, str_data(str), str_len(str), diff --git a/src/lib-index/test-mail-index-transaction-update.c b/src/lib-index/test-mail-index-transaction-update.c index b54c9b9318..af9067b719 100644 --- a/src/lib-index/test-mail-index-transaction-update.c +++ b/src/lib-index/test-mail-index-transaction-update.c @@ -344,12 +344,12 @@ static void test_mail_index_flag_update_random(void) flags = t_new(enum mail_flags, hdr.messages_count + 1); for (r = 0; r < 1000; r++) { - change = rand() % (MAIL_FLAGS_NONRECENT+1); - seq1 = (rand() % hdr.messages_count) + 1; + change = i_rand() % (MAIL_FLAGS_NONRECENT+1); + seq1 = (i_rand() % hdr.messages_count) + 1; seq2 = seq1 == hdr.messages_count ? seq1 : - (rand() % (hdr.messages_count - seq1)) + seq1; + (i_rand() % (hdr.messages_count - seq1)) + seq1; - switch (rand() % 3) { + switch (i_rand() % 3) { case 0: modify_type = MODIFY_ADD; for (seq = seq1; seq <= seq2; seq++) diff --git a/src/lib-index/test-mail-transaction-log-file.c b/src/lib-index/test-mail-transaction-log-file.c index e7af082198..85e0759585 100644 --- a/src/lib-index/test-mail-transaction-log-file.c +++ b/src/lib-index/test-mail-transaction-log-file.c @@ -329,7 +329,7 @@ static void test_mail_transaction_log_file_modseq_offsets(void) test_assert(MODSEQ_MATCH(2, next_offset)); /* do some random testing with cache */ for (unsigned int i = 0; i < LOG_FILE_MODSEQ_CACHE_SIZE*10; i++) { - modseq = (rand() % max_modseq) + 1; + modseq = (i_rand() % max_modseq) + 1; test_assert(mail_transaction_log_file_get_modseq_next_offset(file, modseq, &next_offset) == 0); test_assert(MODSEQ_MATCH(modseq, next_offset)); } @@ -351,7 +351,7 @@ static void test_mail_transaction_log_file_modseq_offsets(void) test_assert(modseq == max_modseq); /* do some random testing with cache */ for (unsigned int i = 0; i < LOG_FILE_MODSEQ_CACHE_SIZE*10; i++) { - modseq = (rand() % max_modseq) + 1; + modseq = (i_rand() % max_modseq) + 1; test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_next_offset[modseq], &modseq_at, &error) == 0); test_assert(modseq_at == modseq); test_assert(mail_transaction_log_file_get_highest_modseq_at(file, modseq_alt_next_offset[modseq], &modseq_at, &error) == 0); diff --git a/src/lib-mail/test-istream-header-filter.c b/src/lib-mail/test-istream-header-filter.c index f7dcbff7cc..7c196f2b54 100644 --- a/src/lib-mail/test-istream-header-filter.c +++ b/src/lib-mail/test-istream-header-filter.c @@ -188,7 +188,7 @@ static void add_random_text(string_t *dest, unsigned int count) unsigned int i; for (i = 0; i < count; i++) - str_append_c(dest, rand() % ('z'-'a'+1) + 'a'); + str_append_c(dest, i_rand() % ('z'-'a'+1) + 'a'); } static void ATTR_NULL(3) diff --git a/src/lib-mail/test-mail-html2text.c b/src/lib-mail/test-mail-html2text.c index d06f5846de..4d051ce966 100644 --- a/src/lib-mail/test-mail-html2text.c +++ b/src/lib-mail/test-mail-html2text.c @@ -87,9 +87,9 @@ static void test_mail_html2text_random(void) ht = mail_html2text_init(0); for (unsigned int i = 0; i < 100; i++) { - s[0] = valid_chars[rand() % N_ELEMENTS(valid_chars)]; - s[1] = valid_chars[rand() % N_ELEMENTS(valid_chars)]; - mail_html2text_more(ht, s, rand()%2+1, str); + s[0] = valid_chars[i_rand() % N_ELEMENTS(valid_chars)]; + s[1] = valid_chars[i_rand() % N_ELEMENTS(valid_chars)]; + mail_html2text_more(ht, s, i_rand()%2+1, str); } mail_html2text_deinit(&ht); str_truncate(str, 0); diff --git a/src/lib-mail/test-message-header-decode.c b/src/lib-mail/test-message-header-decode.c index d6c1939191..09d57effbf 100644 --- a/src/lib-mail/test-message-header-decode.c +++ b/src/lib-mail/test-message-header-decode.c @@ -74,8 +74,8 @@ static void test_message_header_decode_encode_random(void) /* fill only with 7bit data so we don't have to worry about the data being valid UTF-8 */ for (j = 0; j < sizeof(buf); j++) - buf[j] = rand() % 128; - buflen = rand() % sizeof(buf); + buf[j] = i_rand() % 128; + buflen = i_rand() % sizeof(buf); str_truncate(encoded, 0); str_truncate(decoded, 0); diff --git a/src/lib-mail/test-message-header-hash.c b/src/lib-mail/test-message-header-hash.c index 597dda5d3d..5036132b2b 100644 --- a/src/lib-mail/test-message-header-hash.c +++ b/src/lib-mail/test-message-header-hash.c @@ -89,7 +89,7 @@ static void test_message_header_hash_more(void) for (unsigned int j = 0; j < input_len; ) { const unsigned char *input_part = (const unsigned char *)tests[i].input + j; - unsigned int len = rand() % (input_len - j) + 1; + unsigned int len = i_rand() % (input_len - j) + 1; message_header_hash_more(&ctx, &hash_method_md5, &md5_ctx, tests[i].version, input_part, len); diff --git a/src/lib-master/master-login-auth.c b/src/lib-master/master-login-auth.c index f45b9bd606..b33dbcc6d2 100644 --- a/src/lib-master/master-login-auth.c +++ b/src/lib-master/master-login-auth.c @@ -76,7 +76,7 @@ master_login_auth_init(const char *auth_socket_path, bool request_auth_token) auth->refcount = 1; auth->fd = -1; hash_table_create_direct(&auth->requests, pool, 0); - auth->id_counter = (rand() % 32767) * 131072U; + auth->id_counter = (i_rand() % 32767) * 131072U; return auth; } diff --git a/src/lib-master/test-master-service-settings-cache.c b/src/lib-master/test-master-service-settings-cache.c index 12dcd52a10..160eefb196 100644 --- a/src/lib-master/test-master-service-settings-cache.c +++ b/src/lib-master/test-master-service-settings-cache.c @@ -64,15 +64,15 @@ static void test_master_service_settings_cache_once(void) const struct setting_parser_context *parser; const char *error; - output.used_local = output.service_uses_local && (rand() % 2) != 0; + output.used_local = output.service_uses_local && (i_rand() % 2) != 0; if (output.used_local) { input.local_ip.family = AF_INET; - input.local_ip.u.ip4.s_addr = 100 + rand() % 100; + input.local_ip.u.ip4.s_addr = 100 + i_rand() % 100; } - output.used_remote = output.service_uses_remote && (rand() % 2) != 0; + output.used_remote = output.service_uses_remote && (i_rand() % 2) != 0; if (output.used_remote) { input.remote_ip.family = AF_INET; - input.remote_ip.u.ip4.s_addr = 100 + rand() % 100; + input.remote_ip.u.ip4.s_addr = 100 + i_rand() % 100; } test_assert(master_service_settings_cache_read(cache, &input, NULL, &parser, &error) == 0); } diff --git a/src/lib-storage/index/mbox/mbox-lock.c b/src/lib-storage/index/mbox/mbox-lock.c index a804cd4a86..7542241cfe 100644 --- a/src/lib-storage/index/mbox/mbox-lock.c +++ b/src/lib-storage/index/mbox/mbox-lock.c @@ -21,7 +21,7 @@ #endif /* 0.1 .. 0.2msec */ -#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000) +#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)i_rand() % 100000) enum mbox_lock_type { MBOX_LOCK_DOTLOCK, diff --git a/src/lib-test/test-istream.c b/src/lib-test/test-istream.c index 6355aec299..bf5468b951 100644 --- a/src/lib-test/test-istream.c +++ b/src/lib-test/test-istream.c @@ -32,7 +32,7 @@ static ssize_t test_read(struct istream_private *stream) } else { /* copy data to a buffer in somewhat random place. this could help catch bugs. */ - new_skip_diff = rand() % 128; + new_skip_diff = i_rand() % 128; stream->skip = (stream->skip - tstream->skip_diff) + new_skip_diff; stream->pos = (stream->pos - tstream->skip_diff) + diff --git a/src/lib/file-dotlock.c b/src/lib/file-dotlock.c index cf159a6c2c..efbaf02d91 100644 --- a/src/lib/file-dotlock.c +++ b/src/lib/file-dotlock.c @@ -21,7 +21,7 @@ #define DEFAULT_LOCK_SUFFIX ".lock" /* 0.1 .. 0.2msec */ -#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)rand() % 100000) +#define LOCK_RANDOM_USLEEP_TIME (100000 + (unsigned int)i_rand() % 100000) /* Maximum 3 second wait between dotlock checks */ #define LOCK_MAX_WAIT_USECS (1000000 * 3) diff --git a/src/lib/net.c b/src/lib/net.c index 1c65da4cf9..3ae36f1ef3 100644 --- a/src/lib/net.c +++ b/src/lib/net.c @@ -321,7 +321,7 @@ int net_connect_unix_with_retries(const char *path, unsigned int msecs) break; /* busy. wait for a while. */ - usleep(((rand() % 10) + 1) * 10000); + usleep(((i_rand() % 10) + 1) * 10000); if (gettimeofday(&now, NULL) < 0) i_panic("gettimeofday() failed: %m"); } while (timeval_diff_msecs(&now, &start) < (int)msecs); diff --git a/src/lib/test-array.c b/src/lib/test-array.c index 15451d069c..da7225a942 100644 --- a/src/lib/test-array.c +++ b/src/lib/test-array.c @@ -117,7 +117,7 @@ static void test_array_swap(void) } } for (i = 0; i < 1000; i++) - array_swap(&foos[rand()%3], &foos[rand()%3]); + array_swap(&foos[i_rand()%3], &foos[i_rand()%3]); /* Just want size 3, 5, and 7 in any order */ test_assert(array_count(&foos[0]) * array_count(&foos[1]) * array_count(&foos[2]) == 3*5*7); test_assert(array_count(&foos[0]) + array_count(&foos[1]) + array_count(&foos[2]) == 3+5+7); @@ -191,7 +191,7 @@ static void test_array_cmp(void) t_array_init(&arr1, NELEMS); t_array_init(&arr2, NELEMS); for (i = 0; i < NELEMS; i++) { - elems[i] = rand(); + elems[i] = i_rand(); array_append(&arr2, &elems[i], 1); } array_append(&arr1, elems, NELEMS); @@ -201,10 +201,10 @@ static void test_array_cmp(void) test_assert(array_equal_fn_ctx(&arr1, &arr2, test_compare_ushort_fuzz, &fuzz) == TRUE); for (i = 0; i < 256; i++) { - unsigned int j = rand() % NELEMS; + unsigned int j = i_rand() % NELEMS; const unsigned short *ptmp = array_idx(&arr2, j); unsigned short tmp = *ptmp; - unsigned short repl = tmp + deltas[rand() % N_ELEMENTS(deltas)]; + unsigned short repl = tmp + deltas[i_rand() % N_ELEMENTS(deltas)]; array_idx_set(&arr2, j, &repl); test_assert_idx(array_cmp(&arr1, &arr2) == (tmp == repl), i); @@ -247,23 +247,23 @@ static void test_array_cmp_str(void) t_array_init(&arr1, NELEMS); t_array_init(&arr2, NELEMS); for (i = 0; i < NELEMS; i++) { - elemstrs[i] = t_strdup_printf("%x", rand()); /* never 0-length */ + elemstrs[i] = t_strdup_printf("%x", i_rand()); /* never 0-length */ array_append(&arr2, &elemstrs[i], 1); } array_append(&arr1, elemstrs, NELEMS); test_assert(array_cmp(&arr1, &arr2) == TRUE); /* pointers shared, so identical */ test_assert(array_equal_fn(&arr1, &arr2, test_compare_string) == TRUE); /* therefore value same */ for (i = 0; i < 2560; i++) { - unsigned int j = rand() % NELEMS; + unsigned int j = i_rand() % NELEMS; const char *const *ostr_p = array_idx(&arr2, j); const char *ostr = *ostr_p; unsigned int olen = strlen(ostr); - unsigned int rc = rand() % (olen + 1); + unsigned int rc = i_rand() % (olen + 1); char ochar = ostr[rc]; char buf[12]; const char *bufp = buf; memcpy(buf, ostr, olen+1); - buf[rc] = rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN; + buf[rc] = i_rand() % (CHAR_MAX + 1 - CHAR_MIN) + CHAR_MIN; if(rc == olen) buf[rc+1] = '\0'; array_idx_set(&arr2, j, &bufp); diff --git a/src/lib/test-base32.c b/src/lib/test-base32.c index 51fdc5fbb8..673429b9bf 100644 --- a/src/lib/test-base32.c +++ b/src/lib/test-base32.c @@ -151,9 +151,9 @@ static void test_base32_random(void) test_begin("padded base32 encode/decode with random input"); for (i = 0; i < 1000; i++) { - max = rand() % sizeof(buf); + max = i_rand() % sizeof(buf); for (j = 0; j < max; j++) - buf[j] = rand(); + buf[j] = i_rand(); str_truncate(str, 0); str_truncate(dest, 0); @@ -166,9 +166,9 @@ static void test_base32_random(void) test_begin("padded base32hex encode/decode with random input"); for (i = 0; i < 1000; i++) { - max = rand() % sizeof(buf); + max = i_rand() % sizeof(buf); for (j = 0; j < max; j++) - buf[j] = rand(); + buf[j] = i_rand(); str_truncate(str, 0); str_truncate(dest, 0); diff --git a/src/lib/test-base64.c b/src/lib/test-base64.c index b89b4db15f..0c00fb9b88 100644 --- a/src/lib/test-base64.c +++ b/src/lib/test-base64.c @@ -87,9 +87,9 @@ static void test_base64_random(void) test_begin("base64 encode/decode with random input"); for (i = 0; i < 1000; i++) { - max = rand() % sizeof(buf); + max = i_rand() % sizeof(buf); for (j = 0; j < max; j++) - buf[j] = rand(); + buf[j] = i_rand(); str_truncate(str, 0); str_truncate(dest, 0); diff --git a/src/lib/test-buffer.c b/src/lib/test-buffer.c index e9e4db9aa2..73b59441d5 100644 --- a/src/lib/test-buffer.c +++ b/src/lib/test-buffer.c @@ -16,25 +16,25 @@ static void test_buffer_random(void) buf = buffer_create_dynamic(default_pool, 1); for (i = 0; i < BUF_TEST_SIZE; i++) - testdata[i] = rand(); + testdata[i] = i_rand(); memset(shadowbuf, 0, sizeof(shadowbuf)); shadowbuf_size = 0; for (i = 0; i < BUF_TEST_COUNT; i++) { if (buf->used == BUF_TEST_SIZE) { - size = shadowbuf_size = rand() % (buf->used - 1); + size = shadowbuf_size = i_rand() % (buf->used - 1); buffer_set_used_size(buf, size); memset(shadowbuf + shadowbuf_size, 0, BUF_TEST_SIZE - shadowbuf_size); i_assert(buf->used < BUF_TEST_SIZE); } - test = rand() % 6; - zero = rand() % 10 == 0; + test = i_rand() % 6; + zero = i_rand() % 10 == 0; switch (test) { case 0: - pos = rand() % (BUF_TEST_SIZE-1); - size = rand() % (BUF_TEST_SIZE - pos); + pos = i_rand() % (BUF_TEST_SIZE-1); + size = i_rand() % (BUF_TEST_SIZE - pos); if (!zero) { buffer_write(buf, pos, testdata, size); memcpy(shadowbuf + pos, testdata, size); @@ -46,7 +46,7 @@ static void test_buffer_random(void) shadowbuf_size = pos + size; break; case 1: - size = rand() % (BUF_TEST_SIZE - buf->used); + size = i_rand() % (BUF_TEST_SIZE - buf->used); if (!zero) { buffer_append(buf, testdata, size); memcpy(shadowbuf + shadowbuf_size, @@ -58,8 +58,8 @@ static void test_buffer_random(void) shadowbuf_size += size; break; case 2: - pos = rand() % (BUF_TEST_SIZE-1); - size = rand() % (BUF_TEST_SIZE - I_MAX(buf->used, pos)); + pos = i_rand() % (BUF_TEST_SIZE-1); + size = i_rand() % (BUF_TEST_SIZE - I_MAX(buf->used, pos)); if (!zero) { buffer_insert(buf, pos, testdata, size); memmove(shadowbuf + pos + size, @@ -79,8 +79,8 @@ static void test_buffer_random(void) shadowbuf_size = pos + size; break; case 3: - pos = rand() % (BUF_TEST_SIZE-1); - size = rand() % (BUF_TEST_SIZE - pos); + pos = i_rand() % (BUF_TEST_SIZE-1); + size = i_rand() % (BUF_TEST_SIZE - pos); buffer_delete(buf, pos, size); if (pos < shadowbuf_size) { if (pos + size > shadowbuf_size) @@ -97,9 +97,9 @@ static void test_buffer_random(void) case 4: if (shadowbuf_size <= 1) break; - pos = rand() % (shadowbuf_size-1); /* dest */ - pos2 = rand() % (shadowbuf_size-1); /* source */ - size = rand() % (shadowbuf_size - I_MAX(pos, pos2)); + pos = i_rand() % (shadowbuf_size-1); /* dest */ + pos2 = i_rand() % (shadowbuf_size-1); /* source */ + size = i_rand() % (shadowbuf_size - I_MAX(pos, pos2)); buffer_copy(buf, pos, buf, pos2, size); memmove(shadowbuf + pos, shadowbuf + pos2, size); @@ -107,8 +107,8 @@ static void test_buffer_random(void) shadowbuf_size = pos + size; break; case 5: - pos = rand() % (BUF_TEST_SIZE-1); - size = rand() % (BUF_TEST_SIZE - pos); + pos = i_rand() % (BUF_TEST_SIZE-1); + size = i_rand() % (BUF_TEST_SIZE - pos); p = buffer_get_space_unsafe(buf, pos, size); memcpy(p, testdata, size); memcpy(shadowbuf + pos, testdata, size); diff --git a/src/lib/test-data-stack.c b/src/lib/test-data-stack.c index b43d0d1264..40eab77d16 100644 --- a/src/lib/test-data-stack.c +++ b/src/lib/test-data-stack.c @@ -44,7 +44,7 @@ static void test_ds_buffers(void) T_BEGIN { size_t bigleft = t_get_bytes_available(); size_t i; - for (i = 1; i < bigleft-64; i += rand()%32) T_BEGIN { + for (i = 1; i < bigleft-64; i += i_rand()%32) T_BEGIN { unsigned char *p, *p2; size_t left; t_malloc_no0(i); @@ -131,8 +131,8 @@ static void test_ds_recursive(int count, int depth) test_begin("data-stack recursive"); for(i = 0; i < count; i++) T_BEGIN { - int number=rand()%100+50; - int size=rand()%100+50; + int number=i_rand()%100+50; + int size=i_rand()%100+50; test_ds_recurse(depth, number, size); } T_END; test_end(); diff --git a/src/lib/test-hash.c b/src/lib/test-hash.c index 1c1db7111b..6a7a35fc93 100644 --- a/src/lib/test-hash.c +++ b/src/lib/test-hash.c @@ -14,15 +14,15 @@ static void test_hash_random_pool(pool_t pool) keys = i_new(unsigned int, KEYMAX); keyidx = 0; hash_table_create_direct(&hash, pool, 0); for (i = 0; i < KEYMAX; i++) { - key = (rand() % KEYMAX) + 1; - if (rand() % 5 > 0) { + key = (i_rand() % KEYMAX) + 1; + if (i_rand() % 5 > 0) { if (hash_table_lookup(hash, POINTER_CAST(key)) == NULL) { hash_table_insert(hash, POINTER_CAST(key), POINTER_CAST(1)); keys[keyidx++] = key; } } else if (keyidx > 0) { - delidx = rand() % keyidx; + delidx = i_rand() % keyidx; hash_table_remove(hash, POINTER_CAST(keys[delidx])); memmove(&keys[delidx], &keys[delidx+1], (keyidx-delidx-1) * sizeof(*keys)); diff --git a/src/lib/test-istream-concat.c b/src/lib/test-istream-concat.c index 84b229c66f..65a894996a 100644 --- a/src/lib/test-istream-concat.c +++ b/src/lib/test-istream-concat.c @@ -63,10 +63,10 @@ static bool test_istream_concat_random(void) size_t size = 0; unsigned int i, j, offset, stream_count, data_len, simult; - stream_count = (rand() % TEST_MAX_ISTREAM_COUNT) + 2; + stream_count = (i_rand() % TEST_MAX_ISTREAM_COUNT) + 2; streams = t_new(struct istream *, stream_count + 1); for (i = 0, offset = 0; i < stream_count; i++) { - data_len = rand() % TEST_MAX_ISTREAM_SIZE + 1; + data_len = i_rand() % TEST_MAX_ISTREAM_SIZE + 1; w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) w_data[j] = offset++; @@ -79,7 +79,7 @@ static bool test_istream_concat_random(void) concat = i_stream_create_concat(streams); i_stream_set_max_buffer_size(concat, TEST_MAX_BUFFER_SIZE); - simult = rand() % TEST_MAX_ISTREAM_COUNT; + simult = i_rand() % TEST_MAX_ISTREAM_COUNT; if (simult > 0) { limits = t_new(struct istream *, simult); for (i = 0; i < simult; i++) @@ -87,9 +87,9 @@ static bool test_istream_concat_random(void) } for (i = 0; i < 1000; i++) { - struct istream *input = (simult == 0) ? concat : limits[rand() % simult]; - if (rand() % 3 == 0) { - i_stream_seek(input, rand() % offset); + struct istream *input = (simult == 0) ? concat : limits[i_rand() % simult]; + if (i_rand() % 3 == 0) { + i_stream_seek(input, i_rand() % offset); } else { ssize_t ret = i_stream_read(input); size = i_stream_get_data_size(input); @@ -98,7 +98,7 @@ static bool test_istream_concat_random(void) } else if (input->v_offset + size != offset) { test_assert(ret > 0); test_assert(input->v_offset + ret <= offset); - i_stream_skip(input, rand() % ret); + i_stream_skip(input, i_rand() % ret); data = i_stream_get_data(input, &size); for (j = 0; j < size; j++) { diff --git a/src/lib/test-istream-crlf.c b/src/lib/test-istream-crlf.c index e756c18cf4..2fe9c2631b 100644 --- a/src/lib/test-istream-crlf.c +++ b/src/lib/test-istream-crlf.c @@ -98,7 +98,7 @@ void test_istream_crlf(void) char buf[100]; size_t len = 0; while (len < sizeof(buf) - 1) { - switch(rand()%16) { + switch(i_rand()%16) { case 0: goto outahere; case 1: buf[len] = '\r'; break; case 2: buf[len] = '\n'; break; diff --git a/src/lib/test-istream-seekable.c b/src/lib/test-istream-seekable.c index e85bcb681a..052825abba 100644 --- a/src/lib/test-istream-seekable.c +++ b/src/lib/test-istream-seekable.c @@ -73,10 +73,10 @@ static void test_istream_seekable_random(void) size_t size; unsigned int i, j, offset, stream_count, data_len, buffer_size; - stream_count = (rand() % 10) + 2; + stream_count = (i_rand() % 10) + 2; streams = t_new(struct istream *, stream_count + 1); for (i = 0, offset = 0; i < stream_count; i++) { - data_len = rand() % 100 + 1; + data_len = i_rand() % 100 + 1; w_data = t_malloc_no0(data_len); for (j = 0; j < data_len; j++) w_data[j] = offset++; @@ -87,7 +87,7 @@ static void test_istream_seekable_random(void) streams[i] = NULL; i_assert(offset > 0); - buffer_size = (rand() % 100) + 1; size = 0; + buffer_size = (i_rand() % 100) + 1; size = 0; input = i_stream_create_seekable(streams, buffer_size, fd_callback, NULL); /* first read it through */ @@ -98,8 +98,8 @@ static void test_istream_seekable_random(void) i_stream_seek(input, 0); for (i = 0; i < 100; i++) { - if (rand() % 3 == 0) { - i_stream_seek(input, rand() % offset); + if (i_rand() % 3 == 0) { + i_stream_seek(input, i_rand() % offset); } else { ssize_t ret = i_stream_read(input); if (input->v_offset + size == offset) @@ -109,7 +109,7 @@ static void test_istream_seekable_random(void) } else { test_assert(ret > 0); test_assert(input->v_offset + ret <= offset); - i_stream_skip(input, rand() % (ret+1)); + i_stream_skip(input, i_rand() % (ret+1)); data = i_stream_get_data(input, &size); for (j = 0; j < size; j++) { diff --git a/src/lib/test-istream-tee.c b/src/lib/test-istream-tee.c index 68cb514d14..d22438fa67 100644 --- a/src/lib/test-istream-tee.c +++ b/src/lib/test-istream-tee.c @@ -34,7 +34,7 @@ static void test_istream_tee_tailing(const char *str) test_assert_idx(i_stream_read(child_input[i]) == 0, len); test_assert_idx(!tee_i_stream_child_is_waiting(child_input[i]), len); } - delta = rand() % 32; /* may stand still */ + delta = i_rand() % 32; /* may stand still */ if(delta > TEST_BUF_SIZE - len) delta = 1; } @@ -48,7 +48,7 @@ static void test_istream_tee_tailing(const char *str) delta = 1; while ((len += delta) <= TEST_STR_LEN) { - unsigned int lagger = rand() % CHILD_COUNT; + unsigned int lagger = i_rand() % CHILD_COUNT; test_istream_set_size(test_input, len); for (i = 0; i < CHILD_COUNT; i++) { test_assert(i_stream_read(child_input[i]) == -2); @@ -67,7 +67,7 @@ static void test_istream_tee_tailing(const char *str) test_assert(i_stream_read(child_input[i]) == -2); test_assert(!tee_i_stream_child_is_waiting(child_input[i])); } - delta = rand() % 31 + 1; /* mustn't stand still */ + delta = i_rand() % 31 + 1; /* mustn't stand still */ if(delta > TEST_STR_LEN - len) delta = 1; } diff --git a/src/lib/test-ostream-buffer.c b/src/lib/test-ostream-buffer.c index 3e1a75ebd9..cd90a384f4 100644 --- a/src/lib/test-ostream-buffer.c +++ b/src/lib/test-ostream-buffer.c @@ -23,18 +23,18 @@ static void test_ostream_buffer_random_once(void) output = o_stream_create_buffer(buffer); o_stream_cork(output); - size = (rand() % MAX_BUFSIZE) + 1; + size = (i_rand() % MAX_BUFSIZE) + 1; random_fill_weak(randbuf, size); memcpy(buf, randbuf, size); test_assert(o_stream_send(output, buf, size) > 0); for (i = 0; i < 10; i++) { - offset = rand() % (MAX_BUFSIZE*3); - size = (rand() % MAX_BUFSIZE) + 1; + offset = i_rand() % (MAX_BUFSIZE*3); + size = (i_rand() % MAX_BUFSIZE) + 1; random_fill_weak(randbuf, size); memcpy(buf + offset, randbuf, size); test_assert(o_stream_pwrite(output, randbuf, size, offset) == 0); - if (rand() % 10 == 0) + if (i_rand() % 10 == 0) test_assert(o_stream_flush(output) > 0); } diff --git a/src/lib/test-ostream-file.c b/src/lib/test-ostream-file.c index 64bad05140..7d520705c8 100644 --- a/src/lib/test-ostream-file.c +++ b/src/lib/test-ostream-file.c @@ -30,18 +30,18 @@ static void test_ostream_file_random_once(void) output = o_stream_create_fd(fd, MAX_BUFSIZE); o_stream_cork(output); - size = (rand() % MAX_BUFSIZE) + 1; + size = (i_rand() % MAX_BUFSIZE) + 1; random_fill_weak(randbuf, size); memcpy(buf, randbuf, size); test_assert(o_stream_send(output, buf, size) > 0); for (i = 0; i < 10; i++) { - offset = rand() % (MAX_BUFSIZE*3); - size = (rand() % MAX_BUFSIZE) + 1; + offset = i_rand() % (MAX_BUFSIZE*3); + size = (i_rand() % MAX_BUFSIZE) + 1; random_fill_weak(randbuf, size); memcpy(buf + offset, randbuf, size); test_assert(o_stream_pwrite(output, randbuf, size, offset) == 0); - if (rand() % 10 == 0) + if (i_rand() % 10 == 0) test_assert(o_stream_flush(output) > 0); } diff --git a/src/lib/test-priorityq.c b/src/lib/test-priorityq.c index bc5d5fb069..4510d89ed6 100644 --- a/src/lib/test-priorityq.c +++ b/src/lib/test-priorityq.c @@ -79,11 +79,11 @@ void test_priorityq(void) for (i = 0; i < 100; i++) { pq = priorityq_init(cmp_int, 1); for (j = 0; j < PQ_MAX_ITEMS; j++) { - items[j].num = rand(); + items[j].num = i_rand() % INT_MAX; priorityq_add(pq, &items[j].item); } for (j = 0; j < PQ_MAX_ITEMS; j++) { - if (rand() % 3 == 0) { + if (i_rand() % 3 == 0) { priorityq_remove(pq, &items[j].item); items[j].num = -1; } diff --git a/src/lib/test-seq-range-array.c b/src/lib/test-seq-range-array.c index b43564febe..52ffc84c83 100644 --- a/src/lib/test-seq-range-array.c +++ b/src/lib/test-seq-range-array.c @@ -99,9 +99,9 @@ static void test_seq_range_array_random(void) i_array_init(&range, 1); memset(shadowbuf, 0, sizeof(shadowbuf)); for (i = 0; i < SEQ_RANGE_TEST_COUNT; i++) { - seq1 = rand() % SEQ_RANGE_TEST_BUFSIZE; - seq2 = seq1 + rand() % (SEQ_RANGE_TEST_BUFSIZE - seq1); - test = rand() % 4; + seq1 = i_rand() % SEQ_RANGE_TEST_BUFSIZE; + seq2 = seq1 + i_rand() % (SEQ_RANGE_TEST_BUFSIZE - seq1); + test = i_rand() % 4; switch (test) { case 0: ret = seq_range_array_add(&range, seq1) ? 0 : 1; /* FALSE == added */ diff --git a/src/lib/test-strnum.c b/src/lib/test-strnum.c index e6dbf67cf1..997f8ec473 100644 --- a/src/lib/test-strnum.c +++ b/src/lib/test-strnum.c @@ -26,8 +26,8 @@ static int crappy_uintmax_to_str(char *into, uintmax_t val) static void test_str_to_uintmax(void) { unsigned int i=0; - int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0, valbase = rand() * 1000ull; + int randrange = i_rand()%15+1; /* when 1, will max out on 1s */ + uintmax_t value = 0, valbase = i_rand() * 1000ull; int len, ret; char buff[50]; /* totally assumes < 159 bits */ @@ -38,7 +38,7 @@ static void test_str_to_uintmax(void) value = (value << 1) + 1; if (value >= 64) - value -= rand()%randrange; /* don't always test the same numbers */ + value -= i_rand()%randrange; /* don't always test the same numbers */ len = crappy_uintmax_to_str(buff, value); ret = str_to_uintmax(buff, &value_back); test_assert_idx(ret == 0, i); @@ -99,8 +99,8 @@ static int crappy_uintmax_to_str_hex(char *into, uintmax_t val) static void test_str_to_uintmax_hex(void) { unsigned int i=0; - int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0, valbase = rand() * 1000ull; + int randrange = i_rand()%15+1; /* when 1, will max out on 1s */ + uintmax_t value = 0, valbase = i_rand() * 1000ull; int len, ret; char buff[52]; /* totally assumes < 200 bits */ @@ -111,7 +111,7 @@ static void test_str_to_uintmax_hex(void) value = (value << 1) + 1; if (value >= 64) - value -= rand()%randrange; /* don't always test the same numbers */ + value -= i_rand()%randrange; /* don't always test the same numbers */ len = crappy_uintmax_to_str_hex(buff, value); ret = str_to_uintmax_hex(buff, &value_back); test_assert_idx(ret == 0, i); @@ -175,8 +175,8 @@ static int crappy_uintmax_to_str_oct(char *into, uintmax_t val) static void test_str_to_uintmax_oct(void) { unsigned int i=0; - int randrange = rand()%15+1; /* when 1, will max out on 1s */ - uintmax_t value = 0, valbase = rand() * 1000ull; + int randrange = i_rand()%15+1; /* when 1, will max out on 1s */ + uintmax_t value = 0, valbase = i_rand() * 1000ull; int len, ret; char buff[69]; /* totally assumes < 200 bits */ @@ -187,7 +187,7 @@ static void test_str_to_uintmax_oct(void) value = (value << 1) + 1; if (value >= 64) - value -= rand()%randrange; /* don't always test the same numbers */ + value -= i_rand()%randrange; /* don't always test the same numbers */ len = crappy_uintmax_to_str_oct(buff, value); ret = str_to_uintmax_oct(buff, &value_back); test_assert_idx(ret == 0, i); diff --git a/src/lib/test-unichar.c b/src/lib/test-unichar.c index c0c59f03c6..42dc85b336 100644 --- a/src/lib/test-unichar.c +++ b/src/lib/test-unichar.c @@ -50,7 +50,7 @@ void test_unichar(void) /* The bottom 6 bits should be irrelevant to code coverage, only test 000000, 111111, and something in between. */ if ((chr & 63) == 1) - chr += rand() % 62; /* After 0, somewhere between 1 and 62 */ + chr += i_rand() % 62; /* After 0, somewhere between 1 and 62 */ else if ((chr & 63) > 0 && (chr & 63) < 63) chr |= 63; /* After random, straight to 63 */ diff --git a/src/lib/timing.c b/src/lib/timing.c index 283954412e..960db8492e 100644 --- a/src/lib/timing.c +++ b/src/lib/timing.c @@ -42,9 +42,9 @@ void timing_add_usecs(struct timing *timing, uint64_t usecs) unsigned int count = timing->count; unsigned int idx; if (count > RAND_MAX >> 6) - idx = (rand()*((uint64_t)RAND_MAX+1) + rand()) % count; + idx = (i_rand()*((uint64_t)RAND_MAX+1) + i_rand()) % count; else - idx = rand() % count; + idx = i_rand() % count; if (idx < TIMING_SUBSAMPLING_BUFFER) timing->samples[idx] = usecs; } diff --git a/src/login-common/login-proxy.c b/src/login-common/login-proxy.c index 95c058e774..d5ce7461c3 100644 --- a/src/login-common/login-proxy.c +++ b/src/login-common/login-proxy.c @@ -533,7 +533,7 @@ static unsigned int login_proxy_delay_disconnect(struct login_proxy *proxy) processes will disconnect at slightly different times to spread the load. */ timeval_add_msecs(&rec->disconnect_timestamp, - rand() % PROXY_DISCONNECT_INTERVAL_MSECS); + i_rand() % PROXY_DISCONNECT_INTERVAL_MSECS); } rec->num_disconnects_since_ts++; if (proxy->to != NULL) { diff --git a/src/login-common/main.c b/src/login-common/main.c index b161e59e80..3e50770017 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -381,7 +381,7 @@ static void main_preinit(void) /* randomize the initial index in case service_count=1 (although in that case it's unlikely this setting is even used..) */ - login_source_ips_idx = rand() % login_source_ips_count; + login_source_ips_idx = i_rand() % login_source_ips_count; } login_load_modules(); diff --git a/src/master/main.c b/src/master/main.c index 0693d5be75..c19d9a7d39 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -298,7 +298,7 @@ static void instance_update_now(struct master_instance_list *list) if (to_instance != NULL) timeout_remove(&to_instance); - to_instance = timeout_add((3600*12 + rand()%(60*30)) * 1000, + to_instance = timeout_add((3600*12 + i_rand()%(60*30)) * 1000, instance_update_now, list); } diff --git a/src/master/service-monitor.c b/src/master/service-monitor.c index 3cfc5040ac..fe0e2d2141 100644 --- a/src/master/service-monitor.c +++ b/src/master/service-monitor.c @@ -109,7 +109,7 @@ static void service_status_less(struct service_process *process, signal to all of them at once */ process->to_idle = timeout_add((service->idle_kill * 1000) + - (rand() % 100)*10, + (i_rand() % 100)*10, service_process_kill_idle, process); }