summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-11 12:43:37 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-12 14:52:52 +0000
commit3fe055141793d3bbcf0b0b7fc5b95cc24824d333 (patch)
treed05d0f12a4d96761b35e8acec2ca31259e7cfbc1 /testing
parentd92c96e7832ae4c7f9c32eec0d2f7f661a65b73e (diff)
Assert that we don't divide by 0 in random_testing.cc.
This is always true due to the condition function, but if we introduce a bug that makes the condition not be applied, this causes undefined behaviour.
Diffstat (limited to 'testing')
-rw-r--r--testing/random_testing.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/testing/random_testing.cc b/testing/random_testing.cc
index 4e64c1b4..5ea0bc9d 100644
--- a/testing/random_testing.cc
+++ b/testing/random_testing.cc
@@ -299,10 +299,12 @@ int main() {
299 return tox_conference_get_chatlist_size(state.tox()) != 0; 299 return tox_conference_get_chatlist_size(state.tox()) != 0;
300 }, 300 },
301 [](Local_State *state, Random *rnd, std::mt19937 *rng) { 301 [](Local_State *state, Random *rnd, std::mt19937 *rng) {
302 size_t chat_count = tox_conference_get_chatlist_size(state->tox());
303 assert(chat_count != 0); // Condition above.
302 TOX_ERR_CONFERENCE_INVITE err; 304 TOX_ERR_CONFERENCE_INVITE err;
303 tox_conference_invite( 305 tox_conference_invite(
304 state->tox(), rnd->friend_selector(*rng), 306 state->tox(), rnd->friend_selector(*rng),
305 state->next_invite % tox_conference_get_chatlist_size(state->tox()), &err); 307 state->next_invite % chat_count, &err);
306 state->next_invite++; 308 state->next_invite++;
307 assert(err == TOX_ERR_CONFERENCE_INVITE_OK); 309 assert(err == TOX_ERR_CONFERENCE_INVITE_OK);
308 }, 310 },