Remove TOX_DEBUG and have asserts always enabled.

These are cheap asserts. I've also replaced the fprintf's with
`LOGGER_ERROR` calls.
This commit is contained in:
iphydf 2017-01-04 22:37:53 +00:00
parent 583d71680e
commit 8b4eae4038
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
8 changed files with 16 additions and 59 deletions

View File

@ -127,7 +127,6 @@ endif()
option(DEBUG "Enable assertions and other debugging facilities" OFF)
if(DEBUG)
set(MIN_LOGGER_LEVEL DEBUG)
add_definitions(-DTOX_DEBUG=1)
add_cflag("-g3")
endif()

View File

@ -34,7 +34,6 @@ BUILD_AV="yes"
BUILD_TESTING="yes"
TOX_LOGGER="no"
TOX_DEBUG="no"
NCURSES_FOUND="no"
LIBCONFIG_FOUND="no"
@ -93,17 +92,6 @@ AC_ARG_ENABLE([logging],
]
)
AC_ARG_ENABLE([debug],
[AC_HELP_STRING([--enable-debug], [enable debugging (default: disabled)]) ],
[
if test "x$enableval" = "xyes"; then
TOX_DEBUG="yes"
AC_DEFINE([TOX_DEBUG], [], [If debugging enabled])
fi
]
)
AC_ARG_WITH(log-level,
AC_HELP_STRING([--with-log-level=LEVEL],
[Logger levels: TRACE; DEBUG; INFO; WARNING; ERROR ]),

View File

@ -31,10 +31,6 @@
#include <string.h>
#include <strings.h>
#ifdef TOX_DEBUG
#include <assert.h>
#endif // TOX_DEBUG
// You are responsible for freeing the return value!
uint8_t *hex_string_to_bin(const char *hex_string)
{

View File

@ -2813,13 +2813,10 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
break;
#ifdef TOX_DEBUG
default:
fprintf(stderr, "Load state (DHT): contains unrecognized part (len %u, type %u)\n",
length, type);
LOGGER_ERROR(dht->log, "Load state (DHT): contains unrecognized part (len %u, type %u)\n",
length, type);
break;
#endif
}
return 0;
@ -2839,7 +2836,7 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length)
lendian_to_host32(&data32, data);
if (data32 == DHT_STATE_COOKIE_GLOBAL) {
return load_state(dht_load_state_callback, dht, data + cookie_len,
return load_state(dht_load_state_callback, dht->log, dht, data + cookie_len,
length - cookie_len, DHT_STATE_COOKIE_TYPE);
}
}

View File

@ -31,9 +31,7 @@
#include "network.h"
#include "util.h"
#ifdef TOX_DEBUG
#include <assert.h>
#endif
static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata);
@ -1339,9 +1337,7 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
return -3;
}
#ifdef TOX_DEBUG
assert(temp_filenum <= UINT8_MAX);
#endif
uint8_t file_number = temp_filenum;
// We're always receiving at this point.
@ -2785,20 +2781,16 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
}
uint8_t *next_data = friend_save(&temp, cur_data);
#ifdef TOX_DEBUG
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(cur_data, &temp, friend_size()) == 0);
#endif
#endif
cur_data = next_data;
num++;
}
}
#ifdef TOX_DEBUG
assert(cur_data - data == num * friend_size());
#endif
return cur_data - data;
}
@ -2847,11 +2839,9 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
for (i = 0; i < num; ++i) {
struct SAVED_FRIEND temp = { 0 };
const uint8_t *next_data = friend_load(&temp, cur_data);
#ifdef TOX_DEBUG
assert(next_data - cur_data == friend_size());
#ifdef __LP64__
assert(memcmp(&temp, cur_data, friend_size()) == 0);
#endif
#endif
cur_data = next_data;
@ -2922,9 +2912,7 @@ void messenger_save(const Messenger *m, uint8_t *data)
host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL);
data += size32;
#ifdef TOX_DEBUG
assert(sizeof(get_nospam(&(m->fr))) == sizeof(uint32_t));
#endif
assert(sizeof(get_nospam(&m->fr)) == sizeof(uint32_t));
len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
type = MESSENGER_STATE_TYPE_NOSPAMKEYS;
data = z_state_save_subheader(data, len, type);
@ -3075,13 +3063,10 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
return -2;
}
#ifdef TOX_DEBUG
default:
fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n",
length, type);
LOGGER_ERROR(m->log, "Load state: contains unrecognized part (len %u, type %u)\n",
length, type);
break;
#endif
}
return 0;
@ -3101,7 +3086,7 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
lendian_to_host32(data32 + 1, data + sizeof(uint32_t));
if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) {
return load_state(messenger_load_state_callback, m, data + cookie_len,
return load_state(messenger_load_state_callback, m->log, m, data + cookie_len,
length - cookie_len, MESSENGER_STATE_COOKIE_TYPE);
}

View File

@ -550,9 +550,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
/* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */
if (ip.family != AF_INET && ip.family != AF_INET6) {
#ifdef TOX_DEBUG
fprintf(stderr, "Invalid address family: %u\n", ip.family);
#endif
LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family);
return NULL;
}
@ -576,9 +574,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
/* Check for socket error. */
if (!sock_valid(temp->sock)) {
#ifdef TOX_DEBUG
fprintf(stderr, "Failed to get a socket?! %u, %s\n", errno, strerror(errno));
#endif
LOGGER_ERROR(log, "Failed to get a socket?! %u, %s\n", errno, strerror(errno));
free(temp);
if (error) {

View File

@ -116,13 +116,11 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian)
}
/* state load/save */
int load_state(load_state_callback_func load_state_callback, void *outer,
int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer,
const uint8_t *data, uint32_t length, uint16_t cookie_inner)
{
if (!load_state_callback || !data) {
#ifdef TOX_DEBUG
fprintf(stderr, "load_state() called with invalid args.\n");
#endif
LOGGER_ERROR(log, "load_state() called with invalid args.\n");
return -1;
}
@ -139,17 +137,13 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
if (length < length_sub) {
/* file truncated */
#ifdef TOX_DEBUG
fprintf(stderr, "state file too short: %u < %u\n", length, length_sub);
#endif
LOGGER_ERROR(log, "state file too short: %u < %u\n", length, length_sub);
return -1;
}
if (lendian_to_host16((cookie_type >> 16)) != cookie_inner) {
/* something is not matching up in a bad way, give up */
#ifdef DEBUG
fprintf(stderr, "state file garbled: %04x != %04x\n", (cookie_type >> 16), cookie_inner);
#endif
LOGGER_ERROR(log, "state file garbled: %04x != %04x\n", (cookie_type >> 16), cookie_inner);
return -1;
}

View File

@ -29,6 +29,8 @@
#include <stdbool.h>
#include <stdint.h>
#include "logger.h"
#define MIN(a,b) (((a)<(b))?(a):(b))
#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; }
@ -52,7 +54,7 @@ void lendian_to_host32(uint32_t *dest, const uint8_t *lendian);
/* state load/save */
typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
int load_state(load_state_callback_func load_state_callback, void *outer,
int load_state(load_state_callback_func load_state_callback, Logger *log, void *outer,
const uint8_t *data, uint32_t length, uint16_t cookie_inner);
/* Returns -1 if failed or 0 if success */