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.
This commit is contained in:
irungentoo 2015-03-12 12:19:59 -04:00
parent 1eca7b8e67
commit 4ee017078b
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -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;
}