From dd59d99a7a1ef8074e8faf3e0bc2823fc0b01b6f Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 21 Dec 2014 22:12:12 -0500 Subject: [PATCH] Fixed bug in tox_load where names of size TOX_MAX_NAME_LENGTH didn't load. --- auto_tests/tox_test.c | 25 +++++++++++++++++++++++++ toxcore/Messenger.c | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c index 3240f29a..2c157b1c 100644 --- a/auto_tests/tox_test.c +++ b/auto_tests/tox_test.c @@ -166,6 +166,31 @@ START_TEST(test_one) ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == TOX_FAERR_ALREADYSENT, "Adding friend twice worked."); + uint8_t name[TOX_MAX_NAME_LENGTH]; + int i; + + for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) { + name[i] = rand(); + } + + tox_set_name(tox1, name, sizeof(name)); + ck_assert_msg(tox_get_self_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); + + size_t save_size = tox_size(tox1); + uint8_t data[save_size]; + tox_save(tox1, data); + + tox_kill(tox2); + tox2 = tox_new(0); + ck_assert_msg(tox_load(tox2, data, save_size) == 0, "Load failed"); + + size_t length = tox_get_self_name_size(tox2); + ck_assert_msg(tox_get_self_name_size(tox2) == sizeof name, "Wrong name size."); + + uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; + ck_assert_msg(tox_get_self_name(tox2, new_name) == TOX_MAX_NAME_LENGTH, "Wrong name length"); + ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name"); + tox_kill(tox1); tox_kill(tox2); } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 7d93b2da..6264eddd 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2754,7 +2754,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 break; case MESSENGER_STATE_TYPE_NAME: - if ((length > 0) && (length < MAX_NAME_LENGTH)) { + if ((length > 0) && (length <= MAX_NAME_LENGTH)) { setname(m, data, length); }