summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2017-01-04 22:37:53 +0000
committeriphydf <iphydf@users.noreply.github.com>2017-01-11 19:43:08 +0000
commit8b4eae4038db87f2df1c40856c99c3ffca8887fe (patch)
treea3d712f2adf081f56a4295a34f5a8c75523e5a18 /toxcore/Messenger.c
parent583d71680ec12349cd1bedea72ae136d55667ecb (diff)
Remove `TOX_DEBUG` and have asserts always enabled.
These are cheap asserts. I've also replaced the fprintf's with `LOGGER_ERROR` calls.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index cd4c8380..05a7c09e 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -31,9 +31,7 @@
31#include "network.h" 31#include "network.h"
32#include "util.h" 32#include "util.h"
33 33
34#ifdef TOX_DEBUG
35#include <assert.h> 34#include <assert.h>
36#endif
37 35
38 36
39static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata); 37static 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
1339 return -3; 1337 return -3;
1340 } 1338 }
1341 1339
1342#ifdef TOX_DEBUG
1343 assert(temp_filenum <= UINT8_MAX); 1340 assert(temp_filenum <= UINT8_MAX);
1344#endif
1345 uint8_t file_number = temp_filenum; 1341 uint8_t file_number = temp_filenum;
1346 1342
1347 // We're always receiving at this point. 1343 // We're always receiving at this point.
@@ -2785,20 +2781,16 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
2785 } 2781 }
2786 2782
2787 uint8_t *next_data = friend_save(&temp, cur_data); 2783 uint8_t *next_data = friend_save(&temp, cur_data);
2788#ifdef TOX_DEBUG
2789 assert(next_data - cur_data == friend_size()); 2784 assert(next_data - cur_data == friend_size());
2790#ifdef __LP64__ 2785#ifdef __LP64__
2791 assert(memcmp(cur_data, &temp, friend_size()) == 0); 2786 assert(memcmp(cur_data, &temp, friend_size()) == 0);
2792#endif 2787#endif
2793#endif
2794 cur_data = next_data; 2788 cur_data = next_data;
2795 num++; 2789 num++;
2796 } 2790 }
2797 } 2791 }
2798 2792
2799#ifdef TOX_DEBUG
2800 assert(cur_data - data == num * friend_size()); 2793 assert(cur_data - data == num * friend_size());
2801#endif
2802 return cur_data - data; 2794 return cur_data - data;
2803} 2795}
2804 2796
@@ -2847,12 +2839,10 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
2847 for (i = 0; i < num; ++i) { 2839 for (i = 0; i < num; ++i) {
2848 struct SAVED_FRIEND temp = { 0 }; 2840 struct SAVED_FRIEND temp = { 0 };
2849 const uint8_t *next_data = friend_load(&temp, cur_data); 2841 const uint8_t *next_data = friend_load(&temp, cur_data);
2850#ifdef TOX_DEBUG
2851 assert(next_data - cur_data == friend_size()); 2842 assert(next_data - cur_data == friend_size());
2852#ifdef __LP64__ 2843#ifdef __LP64__
2853 assert(memcmp(&temp, cur_data, friend_size()) == 0); 2844 assert(memcmp(&temp, cur_data, friend_size()) == 0);
2854#endif 2845#endif
2855#endif
2856 cur_data = next_data; 2846 cur_data = next_data;
2857 2847
2858 if (temp.status >= 3) { 2848 if (temp.status >= 3) {
@@ -2922,9 +2912,7 @@ void messenger_save(const Messenger *m, uint8_t *data)
2922 host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL); 2912 host_to_lendian32(data, MESSENGER_STATE_COOKIE_GLOBAL);
2923 data += size32; 2913 data += size32;
2924 2914
2925#ifdef TOX_DEBUG 2915 assert(sizeof(get_nospam(&m->fr)) == sizeof(uint32_t));
2926 assert(sizeof(get_nospam(&(m->fr))) == sizeof(uint32_t));
2927#endif
2928 len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE; 2916 len = size32 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE;
2929 type = MESSENGER_STATE_TYPE_NOSPAMKEYS; 2917 type = MESSENGER_STATE_TYPE_NOSPAMKEYS;
2930 data = z_state_save_subheader(data, len, type); 2918 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
3075 return -2; 3063 return -2;
3076 } 3064 }
3077 3065
3078#ifdef TOX_DEBUG
3079
3080 default: 3066 default:
3081 fprintf(stderr, "Load state: contains unrecognized part (len %u, type %u)\n", 3067 LOGGER_ERROR(m->log, "Load state: contains unrecognized part (len %u, type %u)\n",
3082 length, type); 3068 length, type);
3083 break; 3069 break;
3084#endif
3085 } 3070 }
3086 3071
3087 return 0; 3072 return 0;
@@ -3101,7 +3086,7 @@ int messenger_load(Messenger *m, const uint8_t *data, uint32_t length)
3101 lendian_to_host32(data32 + 1, data + sizeof(uint32_t)); 3086 lendian_to_host32(data32 + 1, data + sizeof(uint32_t));
3102 3087
3103 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) { 3088 if (!data32[0] && (data32[1] == MESSENGER_STATE_COOKIE_GLOBAL)) {
3104 return load_state(messenger_load_state_callback, m, data + cookie_len, 3089 return load_state(messenger_load_state_callback, m->log, m, data + cookie_len,
3105 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE); 3090 length - cookie_len, MESSENGER_STATE_COOKIE_TYPE);
3106 } 3091 }
3107 3092