From 3fe055141793d3bbcf0b0b7fc5b95cc24824d333 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 11 Aug 2018 12:43:37 +0000 Subject: 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. --- testing/random_testing.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'testing') 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() { return tox_conference_get_chatlist_size(state.tox()) != 0; }, [](Local_State *state, Random *rnd, std::mt19937 *rng) { + size_t chat_count = tox_conference_get_chatlist_size(state->tox()); + assert(chat_count != 0); // Condition above. TOX_ERR_CONFERENCE_INVITE err; tox_conference_invite( state->tox(), rnd->friend_selector(*rng), - state->next_invite % tox_conference_get_chatlist_size(state->tox()), &err); + state->next_invite % chat_count, &err); state->next_invite++; assert(err == TOX_ERR_CONFERENCE_INVITE_OK); }, -- cgit v1.2.3