summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-21 22:12:12 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-21 22:12:12 -0500
commitdd59d99a7a1ef8074e8faf3e0bc2823fc0b01b6f (patch)
tree63e8337aadbcc1f82b002df3bef269366510a190
parentd1eb793a9c1f21e23644d3b2f35d16e1891162ca (diff)
Fixed bug in tox_load where names of size TOX_MAX_NAME_LENGTH didn't
load.
-rw-r--r--auto_tests/tox_test.c25
-rw-r--r--toxcore/Messenger.c2
2 files changed, 26 insertions, 1 deletions
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)
166 ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == TOX_FAERR_ALREADYSENT, 166 ck_assert_msg(tox_add_friend(tox1, address, message, TOX_MAX_FRIENDREQUEST_LENGTH) == TOX_FAERR_ALREADYSENT,
167 "Adding friend twice worked."); 167 "Adding friend twice worked.");
168 168
169 uint8_t name[TOX_MAX_NAME_LENGTH];
170 int i;
171
172 for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) {
173 name[i] = rand();
174 }
175
176 tox_set_name(tox1, name, sizeof(name));
177 ck_assert_msg(tox_get_self_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
178
179 size_t save_size = tox_size(tox1);
180 uint8_t data[save_size];
181 tox_save(tox1, data);
182
183 tox_kill(tox2);
184 tox2 = tox_new(0);
185 ck_assert_msg(tox_load(tox2, data, save_size) == 0, "Load failed");
186
187 size_t length = tox_get_self_name_size(tox2);
188 ck_assert_msg(tox_get_self_name_size(tox2) == sizeof name, "Wrong name size.");
189
190 uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 };
191 ck_assert_msg(tox_get_self_name(tox2, new_name) == TOX_MAX_NAME_LENGTH, "Wrong name length");
192 ck_assert_msg(memcmp(name, new_name, TOX_MAX_NAME_LENGTH) == 0, "Wrong name");
193
169 tox_kill(tox1); 194 tox_kill(tox1);
170 tox_kill(tox2); 195 tox_kill(tox2);
171} 196}
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
2754 break; 2754 break;
2755 2755
2756 case MESSENGER_STATE_TYPE_NAME: 2756 case MESSENGER_STATE_TYPE_NAME:
2757 if ((length > 0) && (length < MAX_NAME_LENGTH)) { 2757 if ((length > 0) && (length <= MAX_NAME_LENGTH)) {
2758 setname(m, data, length); 2758 setname(m, data, length);
2759 } 2759 }
2760 2760