Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TOX_DEBUG and have asserts always enabled. #381

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
12 changes: 0 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ BUILD_AV="yes"
BUILD_TESTING="yes"

TOX_LOGGER="no"
TOX_DEBUG="no"

NCURSES_FOUND="no"
LIBCONFIG_FOUND="no"
Expand Down Expand Up @@ -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 ]),
Expand Down
4 changes: 0 additions & 4 deletions testing/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 3 additions & 6 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
23 changes: 4 additions & 19 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down
8 changes: 2 additions & 6 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down
14 changes: 4 additions & 10 deletions toxcore/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

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

Expand Down
4 changes: 3 additions & 1 deletion toxcore/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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 */
Expand Down