summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-03-12 12:19:59 -0400
committerirungentoo <irungentoo@gmail.com>2015-03-12 12:19:59 -0400
commit4ee017078b1c8bbdf5f61b17194163768f3b0ad8 (patch)
treee651fb869d847302713190a7e393e5bee9cc83a9
parent1eca7b8e678d8afd886dad7f44b7dc09597238f5 (diff)
tox_new() fixes.
If data is NULL and length non zero, TOX_ERR_NEW_NULL is set. error is set to TOX_ERR_NEW_LOAD_BAD_FORMAT when load fails.
-rw-r--r--toxcore/tox.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 554414b1..20f22e3c 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -93,6 +93,11 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng
93 if (!logger_get_global()) 93 if (!logger_get_global())
94 logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore")); 94 logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore"));
95 95
96 if (data == NULL && length != 0) {
97 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL);
98 return NULL;
99 }
100
96 if (data) { 101 if (data) {
97 if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { 102 if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) {
98 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); 103 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED);
@@ -160,14 +165,11 @@ Tox *tox_new(const struct Tox_Options *options, const uint8_t *data, size_t leng
160 } 165 }
161 166
162 if (messenger_load(m, data, length) == -1) { 167 if (messenger_load(m, data, length) == -1) {
163 /* TODO: uncomment this when tox is stable.
164 tox_kill(m);
165 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); 168 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
166 return NULL; 169 } else {
167 */ 170 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
168 } 171 }
169 172
170 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK);
171 return m; 173 return m;
172} 174}
173 175