From 414f58d89686a8d19299c5ae1e7f5daab1682699 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 14 Apr 2015 17:18:09 -0400 Subject: [PATCH 1/2] correctly handle tox_new errors --- src/toxic.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/toxic.c b/src/toxic.c index 49edb52..258d69f 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -640,7 +640,7 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW if (pwerr == TOX_ERR_DECRYPTION_OK) { m = tox_new(tox_opts, (uint8_t *) plain, plain_len, new_err); - if (*new_err != TOX_ERR_NEW_OK) { + if (m == NULL) { fclose(fp); return NULL; } @@ -658,7 +658,7 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW } else { /* data is not encrypted */ m = tox_new(tox_opts, (uint8_t *) data, len, new_err); - if (*new_err != TOX_ERR_NEW_OK) { + if (m == NULL) { fclose(fp); return NULL; } @@ -671,7 +671,7 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, TOX_ERR_NEW m = tox_new(tox_opts, NULL, 0, new_err); - if (*new_err != TOX_ERR_NEW_OK) + if (m == NULL) return NULL; if (store_data(m, data_path) == -1) @@ -689,14 +689,17 @@ static Tox *load_toxic(char *data_path) TOX_ERR_NEW new_err; Tox *m = load_tox(data_path, &tox_opts, &new_err); - if (new_err != TOX_ERR_NEW_OK && tox_opts.ipv6_enabled) { + if (new_err == TOX_ERR_NEW_PORT_ALLOC && tox_opts.ipv6_enabled) { queue_init_message("Falling back to ipv4"); tox_opts.ipv6_enabled = false; m = load_tox(data_path, &tox_opts, &new_err); } + if (!m) + exit_toxic_err("tox_new returned fatal error %d", new_err); + if (new_err != TOX_ERR_NEW_OK) - exit_toxic_err("Tox network failed to initialize (tox_new failed with error %d)", new_err); + queue_init_message("tox_new returned non-fatal error %d", new_err); init_tox_callbacks(m); load_friendlist(m); From 231078b6b90c27533ce5f101c3460c2b3a7c2557 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 18 May 2015 19:52:22 -0400 Subject: [PATCH 2/2] default tox options on initialization --- src/toxic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/toxic.c b/src/toxic.c index 258d69f..38e8145 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -542,6 +542,8 @@ static void init_tox_callbacks(Tox *m) static void init_tox_options(struct Tox_Options *tox_opts) { + tox_options_default(tox_opts); + tox_opts->ipv6_enabled = !arg_opts.use_ipv4; tox_opts->udp_enabled = !arg_opts.force_tcp; tox_opts->proxy_type = arg_opts.proxy_type; @@ -696,7 +698,7 @@ static Tox *load_toxic(char *data_path) } if (!m) - exit_toxic_err("tox_new returned fatal error %d", new_err); + exit_toxic_err("tox_new returned fatal error", new_err); if (new_err != TOX_ERR_NEW_OK) queue_init_message("tox_new returned non-fatal error %d", new_err);