From 4ee017078b1c8bbdf5f61b17194163768f3b0ad8 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 12 Mar 2015 12:19:59 -0400 Subject: 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. --- toxcore/tox.c | 12 +++++++----- 1 file 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 if (!logger_get_global()) logger_set_global(logger_new(LOGGER_OUTPUT_FILE, LOGGER_LEVEL, "toxcore")); + if (data == NULL && length != 0) { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_NULL); + return NULL; + } + if (data) { if (memcmp(data, TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { 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 } if (messenger_load(m, data, length) == -1) { - /* TODO: uncomment this when tox is stable. - tox_kill(m); SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); - return NULL; - */ + } else { + SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); } - SET_ERROR_PARAMETER(error, TOX_ERR_NEW_OK); return m; } -- cgit v1.2.3