]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Replace rand with i_rand
authorAki Tuomi <aki.tuomi@dovecot.fi>
Wed, 23 Aug 2017 09:59:42 +0000 (12:59 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 7 Sep 2017 08:40:31 +0000 (11:40 +0300)
41 files changed:
src/auth/auth-request.c
src/director/director-test.c
src/director/test-user-directory.c
src/doveadm/dsync/test-dsync-mailbox-tree-sync.c
src/lib-compression/test-compression.c
src/lib-dict/test-dict-client.c
src/lib-fs/fs-randomfail.c
src/lib-fts/test-fts-tokenizer.c
src/lib-index/test-mail-index-transaction-update.c
src/lib-index/test-mail-transaction-log-file.c
src/lib-mail/test-istream-header-filter.c
src/lib-mail/test-mail-html2text.c
src/lib-mail/test-message-header-decode.c
src/lib-mail/test-message-header-hash.c
src/lib-master/master-login-auth.c
src/lib-master/test-master-service-settings-cache.c
src/lib-storage/index/mbox/mbox-lock.c
src/lib-test/test-istream.c
src/lib/file-dotlock.c
src/lib/net.c
src/lib/test-array.c
src/lib/test-base32.c
src/lib/test-base64.c
src/lib/test-buffer.c
src/lib/test-data-stack.c
src/lib/test-hash.c
src/lib/test-istream-concat.c
src/lib/test-istream-crlf.c
src/lib/test-istream-seekable.c
src/lib/test-istream-tee.c
src/lib/test-ostream-buffer.c
src/lib/test-ostream-file.c
src/lib/test-priorityq.c
src/lib/test-seq-range-array.c
src/lib/test-strnum.c
src/lib/test-unichar.c
src/lib/timing.c
src/login-common/login-proxy.c
src/login-common/main.c
src/master/main.c
src/master/service-monitor.c

index dc1aff94c25509981d8fb1dee81e1ce7331b36a5..3f9cde19c3025aa8e6aedc150a7169410eb75728 100644 (file)
@@ -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, &timestamp) < 0) {
index bf1c427dd1167cad1cb89b76112f563b6e8c6bcf..af0ba4830be7d2c30c05a5d86839278e7dd6fb31 100644 (file)
@@ -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);
 }
 
index ad4c69534876f692c87ba93abd5a4d743819e319..2c62992b201a2b8164fa7069b9dc15f0fb6e03ae 100644 (file)
@@ -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);
index f9da9693cfed8ba7c89945a6d90f1ef4528ce543..50f3f70d31e270ceceb48a3b3ab8b962a6eab56a 100644 (file)
@@ -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)
index 7779e5605c28c4584290d4efd632b16ee051c140..9a4702efce13f3b6b0bbc33a30ccac43cffffc22 100644 (file)
@@ -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;
        }
index 3ca362aaed1e58e92e703e08531fc9e5cbbdae08..44561680bfff44b44ed47a8cef4c0f83da34ac62 100644 (file)
@@ -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);
index 563e8603d5763b88c43ff88e6262d0aee4fd9033..37ef24b0cbf442e88469b91d80c49b230bfb3ba3 100644 (file)
@@ -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;
 }
 
index 5d34c0d761c1dee74a44e0cee062e7d2a8f719df..56c77b2d300b813a4c9bed4ad139066130661481 100644 (file)
@@ -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),
index b54c9b9318cc9b7e18532fca093c55eacd770dc3..af9067b719c960be76ade9fc21be2d077e471686 100644 (file)
@@ -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++)
index e7af08219803f59d0e65a4b09064373dfd4fcd8b..85e075958517972a4fc8955785aa8fe0216959ad 100644 (file)
@@ -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);
index f7dcbff7cc7280ccd3dbe97287030ad09f942df0..7c196f2b54da079b9dc7622ea9a76ec6d8e13d5e 100644 (file)
@@ -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)
index d06f5846dec2b2ee41b08127196515c0b153ebf1..4d051ce966966add6cc34a8969d041f21aeeeb30 100644 (file)
@@ -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);
index d6c193919180a27ede358eb61b9503804910ab65..09d57effbf968e1cafaa28df73f9b40f5493644a 100644 (file)
@@ -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);
index 597dda5d3d151e680e43778f2195e371eeca7103..5036132b2b7eb6eb4019f81e063782a202543fa8 100644 (file)
@@ -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);
index f45b9bd606d8a2e8b3eb453270be8d77729d8685..b33dbcc6d29db99ea7a87fc74c0270a0655be079 100644 (file)
@@ -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;
 }
 
index 12dcd52a10e429aa8e56c11510a64001a0d53a22..160eefb1964a831bca060905e3e832fb1cb14397 100644 (file)
@@ -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);
 }
index a804cd4a867e8e331f4ed6c32af5123b511cd9ad..7542241cfecb5e3ea885d783d902fc942fa858d1 100644 (file)
@@ -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,
index 6355aec299a59b8303f424a9fa4d8b9ae5a42b7a..bf5468b9518695d761e33f2e3d571e6c9ac62e43 100644 (file)
@@ -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) +
index cf159a6c2cad75f5f5c270353428ca9f6f5a110b..efbaf02d91a99a4a505995f1a231975f06fcf0bf 100644 (file)
@@ -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)
 
index 1c65da4cf9970f528262adb93ba9dba68508a16a..3ae36f1ef3f29debad8383d4921a0ce3ffca9459 100644 (file)
@@ -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);
index 15451d069cc3f87e9b8520bb6d6ec71982ae9126..da7225a94264968c13a13bfe5a61c5d7bc3500d0 100644 (file)
@@ -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);
index 51fdc5fbb8dc2bd8d45f271b7e4c1c4d17f9fb8e..673429b9bf2d655d9eee3327bcc6d644eef31491 100644 (file)
@@ -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);
index b89b4db15f69a313fb6b8613314af55add802e07..0c00fb9b883761a0753b2447e90a1e6bdc4352a2 100644 (file)
@@ -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);
index e9e4db9aa2688f095b527a3741d6a4b0ec416c4e..73b59441d5832ec2db9ab88501c79a3ad6514043 100644 (file)
@@ -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);
index b43d0d1264c2c162700b3dddee7fb7df3358be5b..40eab77d1633b42cdcd48d868aba5ce5c3db1875 100644 (file)
@@ -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();
index 1c1db7111b5ee51556079e9b2806d6759c1103dd..6a7a35fc93ac4e19753d0ed25f410e7961f33705 100644 (file)
@@ -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));
index 84b229c66fa856b50632a010c200ea7ee9320655..65a894996a86374b290ea943563e149195e43e6b 100644 (file)
@@ -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++) {
index e756c18cf48e62a51cf629b74491c5526ca85d20..2fe9c2631b58a8836a1975a113e264e6ae2120d7 100644 (file)
@@ -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;
index e85bcb681a19eeb7ff470738c7d635bff04f029d..052825abba9785d7a98c87740f7c5412ed2e43a5 100644 (file)
@@ -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++) {
index 68cb514d1443bacab0077d2d99b43d8cccd22686..d22438fa677bfb8000d7a4bb700e7d801ca152ec 100644 (file)
@@ -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;
        }
index 3e1a75ebd9b64a473126e67553ac87981245ddb3..cd90a384f467d733980ef5fc79edb652068eb552 100644 (file)
@@ -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);
        }
 
index 64bad05140ba38906fea39d6a1e171b7f19ff758..7d520705c85938a52b580161022c78b745a002c8 100644 (file)
@@ -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);
        }
 
index bc5d5fb069b9b3bd9bed821e60f3817ef8ec3585..4510d89ed6c20ca14dd3f7e594554d076c61d6d1 100644 (file)
@@ -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;
                        }
index b43564febefab9aa68db51189024a4e294866225..52ffc84c83042a591cae6dbfe78d91a6339fa45a 100644 (file)
@@ -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 */
index e6dbf67cf17b7330cba881b600626daee6e8f0af..997f8ec473fd00d3cd650e09a1171b0606f8b176 100644 (file)
@@ -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);
index c0c59f03c6f251b6902e350de04474ad442044cc..42dc85b33638b679d859ab695e6ac7e19865110f 100644 (file)
@@ -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 */
 
index 283954412ec1b7e1fd65679447ad0614a0672726..960db8492e7c18a0bff46dd6e385952887e81657 100644 (file)
@@ -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;
        }
index 95c058e7743af64bf952916c6be7a27b01364de4..d5ce7461c3feeacfa16164e9ace4f76d90920a05 100644 (file)
@@ -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) {
index b161e59e80c58a954b3898bbabfd819adec61579..3e5077001791842fd2b5d9cd425d84e49320932b 100644 (file)
@@ -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();
index 0693d5be75b1b88444e70f9f8cb1a50cdced4cc5..c19d9a7d395fe53efc9ddff37f84eb85abeac330 100644 (file)
@@ -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);
 }
 
index 3cfc5040ac4963c418176ffec5c6fec1d650a3b9..fe0e2d21413649ea31ac6e77cf8384d15dfae513 100644 (file)
@@ -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);
                }