summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2020-05-02 20:49:41 +0100
committeriphydf <iphydf@users.noreply.github.com>2020-05-02 21:47:08 +0100
commit2570ddcb17fdf5bea56c6bc1c5c2d04ba2068ee7 (patch)
tree621dd5a3953ad786650e50fdba2787009c78df95 /toxcore/tox.c
parente057bae563e133dbab7381ebbe1dc10f93d6eb4f (diff)
Fix errors on error paths found by oomer.
* Use-after-free because we free network before dht in one case. * Various unchecked allocs in tests (not so important). * We used to not check whether ping arrays were actually allocated in DHT. * `ping_kill` and `ping_array_kill` used to crash when passing NULL. Also: * Added an assert in all public API functions to ensure tox isn't NULL. The error message you get from that is a bit nicer than "Segmentation fault" when clients (or our tests) do things wrong. * Decreased the sleep time in iterate_all_wait from 20ms to 5ms. Everything seems to still work with 5ms, and this greatly decreases the amount of time spent per test run, making oomer run much faster.
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 7126631e..d2d3ed34 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -646,6 +646,7 @@ static void end_save(uint8_t *data)
646 646
647size_t tox_get_savedata_size(const Tox *tox) 647size_t tox_get_savedata_size(const Tox *tox)
648{ 648{
649 assert(tox != nullptr);
649 lock(tox); 650 lock(tox);
650 size_t ret = 2 * sizeof(uint32_t) 651 size_t ret = 2 * sizeof(uint32_t)
651 + messenger_size(tox->m) 652 + messenger_size(tox->m)
@@ -657,6 +658,8 @@ size_t tox_get_savedata_size(const Tox *tox)
657 658
658void tox_get_savedata(const Tox *tox, uint8_t *savedata) 659void tox_get_savedata(const Tox *tox, uint8_t *savedata)
659{ 660{
661 assert(tox != nullptr);
662
660 if (savedata == nullptr) { 663 if (savedata == nullptr) {
661 return; 664 return;
662 } 665 }
@@ -682,6 +685,8 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata)
682 685
683bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) 686bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error)
684{ 687{
688 assert(tox != nullptr);
689
685 if (!host || !public_key) { 690 if (!host || !public_key) {
686 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); 691 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
687 return 0; 692 return 0;
@@ -729,6 +734,8 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
729bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, 734bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
730 Tox_Err_Bootstrap *error) 735 Tox_Err_Bootstrap *error)
731{ 736{
737 assert(tox != nullptr);
738
732 if (!host || !public_key) { 739 if (!host || !public_key) {
733 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); 740 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
734 return 0; 741 return 0;
@@ -774,6 +781,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
774 781
775Tox_Connection tox_self_get_connection_status(const Tox *tox) 782Tox_Connection tox_self_get_connection_status(const Tox *tox)
776{ 783{
784 assert(tox != nullptr);
777 lock(tox); 785 lock(tox);
778 const unsigned int ret = onion_connection_status(tox->m->onion_c); 786 const unsigned int ret = onion_connection_status(tox->m->onion_c);
779 unlock(tox); 787 unlock(tox);
@@ -792,11 +800,13 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox)
792 800
793void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) 801void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback)
794{ 802{
803 assert(tox != nullptr);
795 tox->self_connection_status_callback = callback; 804 tox->self_connection_status_callback = callback;
796} 805}
797 806
798uint32_t tox_iteration_interval(const Tox *tox) 807uint32_t tox_iteration_interval(const Tox *tox)
799{ 808{
809 assert(tox != nullptr);
800 lock(tox); 810 lock(tox);
801 uint32_t ret = messenger_run_interval(tox->m); 811 uint32_t ret = messenger_run_interval(tox->m);
802 unlock(tox); 812 unlock(tox);
@@ -805,6 +815,7 @@ uint32_t tox_iteration_interval(const Tox *tox)
805 815
806void tox_iterate(Tox *tox, void *user_data) 816void tox_iterate(Tox *tox, void *user_data)
807{ 817{
818 assert(tox != nullptr);
808 lock(tox); 819 lock(tox);
809 820
810 mono_time_update(tox->mono_time); 821 mono_time_update(tox->mono_time);
@@ -818,6 +829,8 @@ void tox_iterate(Tox *tox, void *user_data)
818 829
819void tox_self_get_address(const Tox *tox, uint8_t *address) 830void tox_self_get_address(const Tox *tox, uint8_t *address)
820{ 831{
832 assert(tox != nullptr);
833
821 if (address) { 834 if (address) {
822 lock(tox); 835 lock(tox);
823 getaddress(tox->m, address); 836 getaddress(tox->m, address);
@@ -827,6 +840,7 @@ void tox_self_get_address(const Tox *tox, uint8_t *address)
827 840
828void tox_self_set_nospam(Tox *tox, uint32_t nospam) 841void tox_self_set_nospam(Tox *tox, uint32_t nospam)
829{ 842{
843 assert(tox != nullptr);
830 lock(tox); 844 lock(tox);
831 set_nospam(tox->m->fr, net_htonl(nospam)); 845 set_nospam(tox->m->fr, net_htonl(nospam));
832 unlock(tox); 846 unlock(tox);
@@ -834,6 +848,7 @@ void tox_self_set_nospam(Tox *tox, uint32_t nospam)
834 848
835uint32_t tox_self_get_nospam(const Tox *tox) 849uint32_t tox_self_get_nospam(const Tox *tox)
836{ 850{
851 assert(tox != nullptr);
837 lock(tox); 852 lock(tox);
838 uint32_t ret = net_ntohl(get_nospam(tox->m->fr)); 853 uint32_t ret = net_ntohl(get_nospam(tox->m->fr));
839 unlock(tox); 854 unlock(tox);
@@ -842,6 +857,8 @@ uint32_t tox_self_get_nospam(const Tox *tox)
842 857
843void tox_self_get_public_key(const Tox *tox, uint8_t *public_key) 858void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
844{ 859{
860 assert(tox != nullptr);
861
845 if (public_key) { 862 if (public_key) {
846 lock(tox); 863 lock(tox);
847 memcpy(public_key, nc_get_self_public_key(tox->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); 864 memcpy(public_key, nc_get_self_public_key(tox->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE);
@@ -851,6 +868,8 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
851 868
852void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key) 869void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
853{ 870{
871 assert(tox != nullptr);
872
854 if (secret_key) { 873 if (secret_key) {
855 lock(tox); 874 lock(tox);
856 memcpy(secret_key, nc_get_self_secret_key(tox->m->net_crypto), CRYPTO_SECRET_KEY_SIZE); 875 memcpy(secret_key, nc_get_self_secret_key(tox->m->net_crypto), CRYPTO_SECRET_KEY_SIZE);
@@ -860,6 +879,8 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
860 879
861bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error) 880bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error)
862{ 881{
882 assert(tox != nullptr);
883
863 if (!name && length != 0) { 884 if (!name && length != 0) {
864 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); 885 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
865 return 0; 886 return 0;
@@ -882,6 +903,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set
882 903
883size_t tox_self_get_name_size(const Tox *tox) 904size_t tox_self_get_name_size(const Tox *tox)
884{ 905{
906 assert(tox != nullptr);
885 lock(tox); 907 lock(tox);
886 size_t ret = m_get_self_name_size(tox->m); 908 size_t ret = m_get_self_name_size(tox->m);
887 unlock(tox); 909 unlock(tox);
@@ -890,6 +912,8 @@ size_t tox_self_get_name_size(const Tox *tox)
890 912
891void tox_self_get_name(const Tox *tox, uint8_t *name) 913void tox_self_get_name(const Tox *tox, uint8_t *name)
892{ 914{
915 assert(tox != nullptr);
916
893 if (name) { 917 if (name) {
894 lock(tox); 918 lock(tox);
895 getself_name(tox->m, name); 919 getself_name(tox->m, name);
@@ -899,6 +923,8 @@ void tox_self_get_name(const Tox *tox, uint8_t *name)
899 923
900bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error) 924bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error)
901{ 925{
926 assert(tox != nullptr);
927
902 if (!status_message && length != 0) { 928 if (!status_message && length != 0) {
903 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); 929 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
904 return 0; 930 return 0;
@@ -919,6 +945,7 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t
919 945
920size_t tox_self_get_status_message_size(const Tox *tox) 946size_t tox_self_get_status_message_size(const Tox *tox)
921{ 947{
948 assert(tox != nullptr);
922 lock(tox); 949 lock(tox);
923 size_t ret = m_get_self_statusmessage_size(tox->m); 950 size_t ret = m_get_self_statusmessage_size(tox->m);
924 unlock(tox); 951 unlock(tox);
@@ -927,6 +954,8 @@ size_t tox_self_get_status_message_size(const Tox *tox)
927 954
928void tox_self_get_status_message(const Tox *tox, uint8_t *status_message) 955void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
929{ 956{
957 assert(tox != nullptr);
958
930 if (status_message) { 959 if (status_message) {
931 lock(tox); 960 lock(tox);
932 m_copy_self_statusmessage(tox->m, status_message); 961 m_copy_self_statusmessage(tox->m, status_message);
@@ -936,6 +965,7 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
936 965
937void tox_self_set_status(Tox *tox, Tox_User_Status status) 966void tox_self_set_status(Tox *tox, Tox_User_Status status)
938{ 967{
968 assert(tox != nullptr);
939 lock(tox); 969 lock(tox);
940 m_set_userstatus(tox->m, status); 970 m_set_userstatus(tox->m, status);
941 unlock(tox); 971 unlock(tox);
@@ -943,6 +973,7 @@ void tox_self_set_status(Tox *tox, Tox_User_Status status)
943 973
944Tox_User_Status tox_self_get_status(const Tox *tox) 974Tox_User_Status tox_self_get_status(const Tox *tox)
945{ 975{
976 assert(tox != nullptr);
946 lock(tox); 977 lock(tox);
947 const uint8_t status = m_get_self_userstatus(tox->m); 978 const uint8_t status = m_get_self_userstatus(tox->m);
948 unlock(tox); 979 unlock(tox);
@@ -990,6 +1021,8 @@ static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add
990uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, 1021uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length,
991 Tox_Err_Friend_Add *error) 1022 Tox_Err_Friend_Add *error)
992{ 1023{
1024 assert(tox != nullptr);
1025
993 if (!address || !message) { 1026 if (!address || !message) {
994 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); 1027 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
995 return UINT32_MAX; 1028 return UINT32_MAX;
@@ -1011,6 +1044,8 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message
1011 1044
1012uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error) 1045uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error)
1013{ 1046{
1047 assert(tox != nullptr);
1048
1014 if (!public_key) { 1049 if (!public_key) {
1015 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); 1050 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
1016 return UINT32_MAX; 1051 return UINT32_MAX;
@@ -1032,6 +1067,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_F
1032 1067
1033bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error) 1068bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error)
1034{ 1069{
1070 assert(tox != nullptr);
1035 lock(tox); 1071 lock(tox);
1036 const int ret = m_delfriend(tox->m, friend_number); 1072 const int ret = m_delfriend(tox->m, friend_number);
1037 unlock(tox); 1073 unlock(tox);
@@ -1048,6 +1084,8 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *
1048 1084
1049uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error) 1085uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error)
1050{ 1086{
1087 assert(tox != nullptr);
1088
1051 if (!public_key) { 1089 if (!public_key) {
1052 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL); 1090 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL);
1053 return UINT32_MAX; 1091 return UINT32_MAX;
@@ -1069,6 +1107,8 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox
1069bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, 1107bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key,
1070 Tox_Err_Friend_Get_Public_Key *error) 1108 Tox_Err_Friend_Get_Public_Key *error)
1071{ 1109{
1110 assert(tox != nullptr);
1111
1072 if (!public_key) { 1112 if (!public_key) {
1073 return 0; 1113 return 0;
1074 } 1114 }
@@ -1088,6 +1128,7 @@ bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *
1088 1128
1089bool tox_friend_exists(const Tox *tox, uint32_t friend_number) 1129bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
1090{ 1130{
1131 assert(tox != nullptr);
1091 lock(tox); 1132 lock(tox);
1092 bool ret = m_friend_exists(tox->m, friend_number); 1133 bool ret = m_friend_exists(tox->m, friend_number);
1093 unlock(tox); 1134 unlock(tox);
@@ -1096,6 +1137,7 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
1096 1137
1097uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error) 1138uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error)
1098{ 1139{
1140 assert(tox != nullptr);
1099 lock(tox); 1141 lock(tox);
1100 const uint64_t timestamp = m_get_last_online(tox->m, friend_number); 1142 const uint64_t timestamp = m_get_last_online(tox->m, friend_number);
1101 unlock(tox); 1143 unlock(tox);
@@ -1111,6 +1153,7 @@ uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_
1111 1153
1112size_t tox_self_get_friend_list_size(const Tox *tox) 1154size_t tox_self_get_friend_list_size(const Tox *tox)
1113{ 1155{
1156 assert(tox != nullptr);
1114 lock(tox); 1157 lock(tox);
1115 size_t ret = count_friendlist(tox->m); 1158 size_t ret = count_friendlist(tox->m);
1116 unlock(tox); 1159 unlock(tox);
@@ -1119,6 +1162,8 @@ size_t tox_self_get_friend_list_size(const Tox *tox)
1119 1162
1120void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list) 1163void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
1121{ 1164{
1165 assert(tox != nullptr);
1166
1122 if (friend_list) { 1167 if (friend_list) {
1123 lock(tox); 1168 lock(tox);
1124 // TODO(irungentoo): size parameter? 1169 // TODO(irungentoo): size parameter?
@@ -1129,6 +1174,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
1129 1174
1130size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) 1175size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
1131{ 1176{
1177 assert(tox != nullptr);
1132 lock(tox); 1178 lock(tox);
1133 const int ret = m_get_name_size(tox->m, friend_number); 1179 const int ret = m_get_name_size(tox->m, friend_number);
1134 unlock(tox); 1180 unlock(tox);
@@ -1144,6 +1190,8 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_
1144 1190
1145bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error) 1191bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error)
1146{ 1192{
1193 assert(tox != nullptr);
1194
1147 if (!name) { 1195 if (!name) {
1148 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); 1196 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
1149 return 0; 1197 return 0;
@@ -1164,11 +1212,13 @@ bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name,
1164 1212
1165void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback) 1213void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback)
1166{ 1214{
1215 assert(tox != nullptr);
1167 tox->friend_name_callback = callback; 1216 tox->friend_name_callback = callback;
1168} 1217}
1169 1218
1170size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) 1219size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
1171{ 1220{
1221 assert(tox != nullptr);
1172 lock(tox); 1222 lock(tox);
1173 const int ret = m_get_statusmessage_size(tox->m, friend_number); 1223 const int ret = m_get_statusmessage_size(tox->m, friend_number);
1174 unlock(tox); 1224 unlock(tox);
@@ -1185,6 +1235,8 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number
1185bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, 1235bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message,
1186 Tox_Err_Friend_Query *error) 1236 Tox_Err_Friend_Query *error)
1187{ 1237{
1238 assert(tox != nullptr);
1239
1188 if (!status_message) { 1240 if (!status_message) {
1189 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); 1241 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
1190 return false; 1242 return false;
@@ -1209,11 +1261,13 @@ bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8
1209 1261
1210void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback) 1262void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *callback)
1211{ 1263{
1264 assert(tox != nullptr);
1212 tox->friend_status_message_callback = callback; 1265 tox->friend_status_message_callback = callback;
1213} 1266}
1214 1267
1215Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) 1268Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
1216{ 1269{
1270 assert(tox != nullptr);
1217 lock(tox); 1271 lock(tox);
1218 const int ret = m_get_userstatus(tox->m, friend_number); 1272 const int ret = m_get_userstatus(tox->m, friend_number);
1219 unlock(tox); 1273 unlock(tox);
@@ -1229,11 +1283,13 @@ Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, To
1229 1283
1230void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) 1284void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback)
1231{ 1285{
1286 assert(tox != nullptr);
1232 tox->friend_status_callback = callback; 1287 tox->friend_status_callback = callback;
1233} 1288}
1234 1289
1235Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) 1290Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
1236{ 1291{
1292 assert(tox != nullptr);
1237 lock(tox); 1293 lock(tox);
1238 const int ret = m_get_friend_connectionstatus(tox->m, friend_number); 1294 const int ret = m_get_friend_connectionstatus(tox->m, friend_number);
1239 unlock(tox); 1295 unlock(tox);
@@ -1249,11 +1305,13 @@ Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
1249 1305
1250void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) 1306void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
1251{ 1307{
1308 assert(tox != nullptr);
1252 tox->friend_connection_status_callback = callback; 1309 tox->friend_connection_status_callback = callback;
1253} 1310}
1254 1311
1255bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error) 1312bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
1256{ 1313{
1314 assert(tox != nullptr);
1257 lock(tox); 1315 lock(tox);
1258 const int ret = m_get_istyping(tox->m, friend_number); 1316 const int ret = m_get_istyping(tox->m, friend_number);
1259 unlock(tox); 1317 unlock(tox);
@@ -1269,11 +1327,13 @@ bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Frien
1269 1327
1270void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback) 1328void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback)
1271{ 1329{
1330 assert(tox != nullptr);
1272 tox->friend_typing_callback = callback; 1331 tox->friend_typing_callback = callback;
1273} 1332}
1274 1333
1275bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error) 1334bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error)
1276{ 1335{
1336 assert(tox != nullptr);
1277 lock(tox); 1337 lock(tox);
1278 1338
1279 if (m_set_usertyping(tox->m, friend_number, typing) == -1) { 1339 if (m_set_usertyping(tox->m, friend_number, typing) == -1) {
@@ -1324,6 +1384,8 @@ static void set_message_error(const Logger *log, int ret, Tox_Err_Friend_Send_Me
1324uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message, 1384uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message,
1325 size_t length, Tox_Err_Friend_Send_Message *error) 1385 size_t length, Tox_Err_Friend_Send_Message *error)
1326{ 1386{
1387 assert(tox != nullptr);
1388
1327 if (!message) { 1389 if (!message) {
1328 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); 1390 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL);
1329 return 0; 1391 return 0;
@@ -1344,16 +1406,19 @@ uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_T
1344 1406
1345void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback) 1407void tox_callback_friend_read_receipt(Tox *tox, tox_friend_read_receipt_cb *callback)
1346{ 1408{
1409 assert(tox != nullptr);
1347 tox->friend_read_receipt_callback = callback; 1410 tox->friend_read_receipt_callback = callback;
1348} 1411}
1349 1412
1350void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback) 1413void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback)
1351{ 1414{
1415 assert(tox != nullptr);
1352 tox->friend_request_callback = callback; 1416 tox->friend_request_callback = callback;
1353} 1417}
1354 1418
1355void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) 1419void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback)
1356{ 1420{
1421 assert(tox != nullptr);
1357 tox->friend_message_callback = callback; 1422 tox->friend_message_callback = callback;
1358} 1423}
1359 1424
@@ -1370,6 +1435,7 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
1370bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control, 1435bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
1371 Tox_Err_File_Control *error) 1436 Tox_Err_File_Control *error)
1372{ 1437{
1438 assert(tox != nullptr);
1373 lock(tox); 1439 lock(tox);
1374 const int ret = file_control(tox->m, friend_number, file_number, control); 1440 const int ret = file_control(tox->m, friend_number, file_number, control);
1375 unlock(tox); 1441 unlock(tox);
@@ -1420,6 +1486,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, To
1420bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, 1486bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
1421 Tox_Err_File_Seek *error) 1487 Tox_Err_File_Seek *error)
1422{ 1488{
1489 assert(tox != nullptr);
1423 lock(tox); 1490 lock(tox);
1424 const int ret = file_seek(tox->m, friend_number, file_number, position); 1491 const int ret = file_seek(tox->m, friend_number, file_number, position);
1425 unlock(tox); 1492 unlock(tox);
@@ -1462,12 +1529,15 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
1462 1529
1463void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) 1530void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
1464{ 1531{
1532 assert(tox != nullptr);
1465 tox->file_recv_control_callback = callback; 1533 tox->file_recv_control_callback = callback;
1466} 1534}
1467 1535
1468bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, 1536bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
1469 Tox_Err_File_Get *error) 1537 Tox_Err_File_Get *error)
1470{ 1538{
1539 assert(tox != nullptr);
1540
1471 if (!file_id) { 1541 if (!file_id) {
1472 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); 1542 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL);
1473 return 0; 1543 return 0;
@@ -1494,6 +1564,8 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
1494uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id, 1564uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
1495 const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error) 1565 const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error)
1496{ 1566{
1567 assert(tox != nullptr);
1568
1497 if (filename_length && !filename) { 1569 if (filename_length && !filename) {
1498 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); 1570 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
1499 return UINT32_MAX; 1571 return UINT32_MAX;
@@ -1541,6 +1613,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
1541bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, 1613bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
1542 size_t length, Tox_Err_File_Send_Chunk *error) 1614 size_t length, Tox_Err_File_Send_Chunk *error)
1543{ 1615{
1616 assert(tox != nullptr);
1544 lock(tox); 1617 lock(tox);
1545 const int ret = file_data(tox->m, friend_number, file_number, position, data, length); 1618 const int ret = file_data(tox->m, friend_number, file_number, position, data, length);
1546 unlock(tox); 1619 unlock(tox);
@@ -1586,51 +1659,61 @@ bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number,
1586 1659
1587void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback) 1660void tox_callback_file_chunk_request(Tox *tox, tox_file_chunk_request_cb *callback)
1588{ 1661{
1662 assert(tox != nullptr);
1589 tox->file_chunk_request_callback = callback; 1663 tox->file_chunk_request_callback = callback;
1590} 1664}
1591 1665
1592void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback) 1666void tox_callback_file_recv(Tox *tox, tox_file_recv_cb *callback)
1593{ 1667{
1668 assert(tox != nullptr);
1594 tox->file_recv_callback = callback; 1669 tox->file_recv_callback = callback;
1595} 1670}
1596 1671
1597void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback) 1672void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback)
1598{ 1673{
1674 assert(tox != nullptr);
1599 tox->file_recv_chunk_callback = callback; 1675 tox->file_recv_chunk_callback = callback;
1600} 1676}
1601 1677
1602void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) 1678void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback)
1603{ 1679{
1680 assert(tox != nullptr);
1604 tox->conference_invite_callback = callback; 1681 tox->conference_invite_callback = callback;
1605} 1682}
1606 1683
1607void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback) 1684void tox_callback_conference_connected(Tox *tox, tox_conference_connected_cb *callback)
1608{ 1685{
1686 assert(tox != nullptr);
1609 tox->conference_connected_callback = callback; 1687 tox->conference_connected_callback = callback;
1610} 1688}
1611 1689
1612void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) 1690void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback)
1613{ 1691{
1692 assert(tox != nullptr);
1614 tox->conference_message_callback = callback; 1693 tox->conference_message_callback = callback;
1615} 1694}
1616 1695
1617void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) 1696void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback)
1618{ 1697{
1698 assert(tox != nullptr);
1619 tox->conference_title_callback = callback; 1699 tox->conference_title_callback = callback;
1620} 1700}
1621 1701
1622void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback) 1702void tox_callback_conference_peer_name(Tox *tox, tox_conference_peer_name_cb *callback)
1623{ 1703{
1704 assert(tox != nullptr);
1624 tox->conference_peer_name_callback = callback; 1705 tox->conference_peer_name_callback = callback;
1625} 1706}
1626 1707
1627void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback) 1708void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_list_changed_cb *callback)
1628{ 1709{
1710 assert(tox != nullptr);
1629 tox->conference_peer_list_changed_callback = callback; 1711 tox->conference_peer_list_changed_callback = callback;
1630} 1712}
1631 1713
1632uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error) 1714uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
1633{ 1715{
1716 assert(tox != nullptr);
1634 lock(tox); 1717 lock(tox);
1635 const int ret = add_groupchat(tox->m->conferences_object, GROUPCHAT_TYPE_TEXT); 1718 const int ret = add_groupchat(tox->m->conferences_object, GROUPCHAT_TYPE_TEXT);
1636 unlock(tox); 1719 unlock(tox);
@@ -1646,6 +1729,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
1646 1729
1647bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error) 1730bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
1648{ 1731{
1732 assert(tox != nullptr);
1649 lock(tox); 1733 lock(tox);
1650 const int ret = del_groupchat(tox->m->conferences_object, conference_number, true); 1734 const int ret = del_groupchat(tox->m->conferences_object, conference_number, true);
1651 unlock(tox); 1735 unlock(tox);
@@ -1661,6 +1745,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Confere
1661 1745
1662uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error) 1746uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error)
1663{ 1747{
1748 assert(tox != nullptr);
1664 lock(tox); 1749 lock(tox);
1665 const int ret = group_number_peers(tox->m->conferences_object, conference_number, false); 1750 const int ret = group_number_peers(tox->m->conferences_object, conference_number, false);
1666 unlock(tox); 1751 unlock(tox);
@@ -1677,6 +1762,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T
1677size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1762size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1678 Tox_Err_Conference_Peer_Query *error) 1763 Tox_Err_Conference_Peer_Query *error)
1679{ 1764{
1765 assert(tox != nullptr);
1680 lock(tox); 1766 lock(tox);
1681 const int ret = group_peername_size(tox->m->conferences_object, conference_number, peer_number, false); 1767 const int ret = group_peername_size(tox->m->conferences_object, conference_number, peer_number, false);
1682 unlock(tox); 1768 unlock(tox);
@@ -1698,6 +1784,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num
1698bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, 1784bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name,
1699 Tox_Err_Conference_Peer_Query *error) 1785 Tox_Err_Conference_Peer_Query *error)
1700{ 1786{
1787 assert(tox != nullptr);
1701 lock(tox); 1788 lock(tox);
1702 const int ret = group_peername(tox->m->conferences_object, conference_number, peer_number, name, false); 1789 const int ret = group_peername(tox->m->conferences_object, conference_number, peer_number, name, false);
1703 unlock(tox); 1790 unlock(tox);
@@ -1719,6 +1806,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
1719bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1806bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1720 uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) 1807 uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
1721{ 1808{
1809 assert(tox != nullptr);
1722 lock(tox); 1810 lock(tox);
1723 const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, peer_number, public_key, false); 1811 const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, peer_number, public_key, false);
1724 unlock(tox); 1812 unlock(tox);
@@ -1740,6 +1828,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb
1740bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1828bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1741 Tox_Err_Conference_Peer_Query *error) 1829 Tox_Err_Conference_Peer_Query *error)
1742{ 1830{
1831 assert(tox != nullptr);
1743 lock(tox); 1832 lock(tox);
1744 const int ret = group_peernumber_is_ours(tox->m->conferences_object, conference_number, peer_number); 1833 const int ret = group_peernumber_is_ours(tox->m->conferences_object, conference_number, peer_number);
1745 unlock(tox); 1834 unlock(tox);
@@ -1765,6 +1854,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb
1765uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number, 1854uint32_t tox_conference_offline_peer_count(const Tox *tox, uint32_t conference_number,
1766 Tox_Err_Conference_Peer_Query *error) 1855 Tox_Err_Conference_Peer_Query *error)
1767{ 1856{
1857 assert(tox != nullptr);
1768 lock(tox); 1858 lock(tox);
1769 const int ret = group_number_peers(tox->m->conferences_object, conference_number, true); 1859 const int ret = group_number_peers(tox->m->conferences_object, conference_number, true);
1770 unlock(tox); 1860 unlock(tox);
@@ -1782,6 +1872,7 @@ size_t tox_conference_offline_peer_get_name_size(const Tox *tox, uint32_t confer
1782 uint32_t offline_peer_number, 1872 uint32_t offline_peer_number,
1783 Tox_Err_Conference_Peer_Query *error) 1873 Tox_Err_Conference_Peer_Query *error)
1784{ 1874{
1875 assert(tox != nullptr);
1785 lock(tox); 1876 lock(tox);
1786 const int ret = group_peername_size(tox->m->conferences_object, conference_number, offline_peer_number, true); 1877 const int ret = group_peername_size(tox->m->conferences_object, conference_number, offline_peer_number, true);
1787 unlock(tox); 1878 unlock(tox);
@@ -1804,6 +1895,7 @@ bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_nu
1804 uint8_t *name, 1895 uint8_t *name,
1805 Tox_Err_Conference_Peer_Query *error) 1896 Tox_Err_Conference_Peer_Query *error)
1806{ 1897{
1898 assert(tox != nullptr);
1807 lock(tox); 1899 lock(tox);
1808 const int ret = group_peername(tox->m->conferences_object, conference_number, offline_peer_number, name, true); 1900 const int ret = group_peername(tox->m->conferences_object, conference_number, offline_peer_number, name, true);
1809 unlock(tox); 1901 unlock(tox);
@@ -1826,6 +1918,7 @@ bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t confere
1826 uint32_t offline_peer_number, 1918 uint32_t offline_peer_number,
1827 uint8_t *public_key, Tox_Err_Conference_Peer_Query *error) 1919 uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
1828{ 1920{
1921 assert(tox != nullptr);
1829 lock(tox); 1922 lock(tox);
1830 const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, offline_peer_number, public_key, true); 1923 const int ret = group_peer_pubkey(tox->m->conferences_object, conference_number, offline_peer_number, public_key, true);
1831 unlock(tox); 1924 unlock(tox);
@@ -1848,6 +1941,7 @@ uint64_t tox_conference_offline_peer_get_last_active(const Tox *tox, uint32_t co
1848 uint32_t offline_peer_number, 1941 uint32_t offline_peer_number,
1849 Tox_Err_Conference_Peer_Query *error) 1942 Tox_Err_Conference_Peer_Query *error)
1850{ 1943{
1944 assert(tox != nullptr);
1851 uint64_t last_active = UINT64_MAX; 1945 uint64_t last_active = UINT64_MAX;
1852 lock(tox); 1946 lock(tox);
1853 const int ret = group_frozen_last_active(tox->m->conferences_object, conference_number, offline_peer_number, 1947 const int ret = group_frozen_last_active(tox->m->conferences_object, conference_number, offline_peer_number,
@@ -1872,6 +1966,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number,
1872 uint32_t max_offline_peers, 1966 uint32_t max_offline_peers,
1873 Tox_Err_Conference_Set_Max_Offline *error) 1967 Tox_Err_Conference_Set_Max_Offline *error)
1874{ 1968{
1969 assert(tox != nullptr);
1875 lock(tox); 1970 lock(tox);
1876 const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers); 1971 const int ret = group_set_max_frozen(tox->m->conferences_object, conference_number, max_offline_peers);
1877 unlock(tox); 1972 unlock(tox);
@@ -1888,6 +1983,7 @@ bool tox_conference_set_max_offline(Tox *tox, uint32_t conference_number,
1888bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, 1983bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number,
1889 Tox_Err_Conference_Invite *error) 1984 Tox_Err_Conference_Invite *error)
1890{ 1985{
1986 assert(tox != nullptr);
1891 lock(tox); 1987 lock(tox);
1892 const int ret = invite_friend(tox->m->conferences_object, friend_number, conference_number); 1988 const int ret = invite_friend(tox->m->conferences_object, friend_number, conference_number);
1893 unlock(tox); 1989 unlock(tox);
@@ -1913,6 +2009,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference
1913uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, 2009uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length,
1914 Tox_Err_Conference_Join *error) 2010 Tox_Err_Conference_Join *error)
1915{ 2011{
2012 assert(tox != nullptr);
1916 lock(tox); 2013 lock(tox);
1917 const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); 2014 const int ret = join_groupchat(tox->m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
1918 unlock(tox); 2015 unlock(tox);
@@ -1950,6 +2047,7 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
1950bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message, 2047bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message,
1951 size_t length, Tox_Err_Conference_Send_Message *error) 2048 size_t length, Tox_Err_Conference_Send_Message *error)
1952{ 2049{
2050 assert(tox != nullptr);
1953 lock(tox); 2051 lock(tox);
1954 int ret = 0; 2052 int ret = 0;
1955 2053
@@ -1985,6 +2083,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Messa
1985 2083
1986size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error) 2084size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error)
1987{ 2085{
2086 assert(tox != nullptr);
1988 lock(tox); 2087 lock(tox);
1989 const int ret = group_title_get_size(tox->m->conferences_object, conference_number); 2088 const int ret = group_title_get_size(tox->m->conferences_object, conference_number);
1990 unlock(tox); 2089 unlock(tox);
@@ -2006,6 +2105,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number,
2006bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, 2105bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title,
2007 Tox_Err_Conference_Title *error) 2106 Tox_Err_Conference_Title *error)
2008{ 2107{
2108 assert(tox != nullptr);
2009 lock(tox); 2109 lock(tox);
2010 const int ret = group_title_get(tox->m->conferences_object, conference_number, title); 2110 const int ret = group_title_get(tox->m->conferences_object, conference_number, title);
2011 unlock(tox); 2111 unlock(tox);
@@ -2027,6 +2127,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_
2027bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, 2127bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length,
2028 Tox_Err_Conference_Title *error) 2128 Tox_Err_Conference_Title *error)
2029{ 2129{
2130 assert(tox != nullptr);
2030 lock(tox); 2131 lock(tox);
2031 const int ret = group_title_send(tox->m->conferences_object, conference_number, title, length); 2132 const int ret = group_title_send(tox->m->conferences_object, conference_number, title, length);
2032 unlock(tox); 2133 unlock(tox);
@@ -2051,6 +2152,7 @@ bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_
2051 2152
2052size_t tox_conference_get_chatlist_size(const Tox *tox) 2153size_t tox_conference_get_chatlist_size(const Tox *tox)
2053{ 2154{
2155 assert(tox != nullptr);
2054 lock(tox); 2156 lock(tox);
2055 size_t ret = count_chatlist(tox->m->conferences_object); 2157 size_t ret = count_chatlist(tox->m->conferences_object);
2056 unlock(tox); 2158 unlock(tox);
@@ -2059,6 +2161,7 @@ size_t tox_conference_get_chatlist_size(const Tox *tox)
2059 2161
2060void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist) 2162void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
2061{ 2163{
2164 assert(tox != nullptr);
2062 lock(tox); 2165 lock(tox);
2063 const size_t list_size = count_chatlist(tox->m->conferences_object); 2166 const size_t list_size = count_chatlist(tox->m->conferences_object);
2064 copy_chatlist(tox->m->conferences_object, chatlist, list_size); 2167 copy_chatlist(tox->m->conferences_object, chatlist, list_size);
@@ -2068,6 +2171,7 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
2068Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number, 2171Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number,
2069 Tox_Err_Conference_Get_Type *error) 2172 Tox_Err_Conference_Get_Type *error)
2070{ 2173{
2174 assert(tox != nullptr);
2071 lock(tox); 2175 lock(tox);
2072 const int ret = group_get_type(tox->m->conferences_object, conference_number); 2176 const int ret = group_get_type(tox->m->conferences_object, conference_number);
2073 unlock(tox); 2177 unlock(tox);
@@ -2084,6 +2188,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_
2084/* id is TOX_CONFERENCE_ID_SIZE bytes */ 2188/* id is TOX_CONFERENCE_ID_SIZE bytes */
2085bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id) 2189bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id)
2086{ 2190{
2191 assert(tox != nullptr);
2087 lock(tox); 2192 lock(tox);
2088 bool ret = conference_get_id(tox->m->conferences_object, conference_number, id); 2193 bool ret = conference_get_id(tox->m->conferences_object, conference_number, id);
2089 unlock(tox); 2194 unlock(tox);
@@ -2094,11 +2199,14 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *
2094/* uid is TOX_CONFERENCE_ID_SIZE bytes */ 2199/* uid is TOX_CONFERENCE_ID_SIZE bytes */
2095bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid) 2200bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid)
2096{ 2201{
2202 assert(tox != nullptr);
2097 return tox_conference_get_id(tox, conference_number, uid); 2203 return tox_conference_get_id(tox, conference_number, uid);
2098} 2204}
2099 2205
2100uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error) 2206uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error)
2101{ 2207{
2208 assert(tox != nullptr);
2209
2102 if (!id) { 2210 if (!id) {
2103 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL); 2211 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_BY_ID_NULL);
2104 return UINT32_MAX; 2212 return UINT32_MAX;
@@ -2120,6 +2228,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere
2120// TODO(iphydf): Delete in 0.3.0. 2228// TODO(iphydf): Delete in 0.3.0.
2121uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) 2229uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error)
2122{ 2230{
2231 assert(tox != nullptr);
2123 Tox_Err_Conference_By_Id id_error; 2232 Tox_Err_Conference_By_Id id_error;
2124 const uint32_t res = tox_conference_by_id(tox, uid, &id_error); 2233 const uint32_t res = tox_conference_by_id(tox, uid, &id_error);
2125 2234
@@ -2172,6 +2281,8 @@ static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error
2172bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, 2281bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
2173 Tox_Err_Friend_Custom_Packet *error) 2282 Tox_Err_Friend_Custom_Packet *error)
2174{ 2283{
2284 assert(tox != nullptr);
2285
2175 if (!data) { 2286 if (!data) {
2176 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); 2287 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
2177 return 0; 2288 return 0;
@@ -2202,6 +2313,8 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
2202 2313
2203void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback) 2314void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback)
2204{ 2315{
2316 assert(tox != nullptr);
2317
2205 /* start at PACKET_ID_RANGE_LOSSY_CUSTOM_START so ToxAV Packets are excluded */ 2318 /* start at PACKET_ID_RANGE_LOSSY_CUSTOM_START so ToxAV Packets are excluded */
2206 for (uint8_t i = PACKET_ID_RANGE_LOSSY_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSY_END; ++i) { 2319 for (uint8_t i = PACKET_ID_RANGE_LOSSY_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSY_END; ++i) {
2207 tox->friend_lossy_packet_callback_per_pktid[i] = callback; 2320 tox->friend_lossy_packet_callback_per_pktid[i] = callback;
@@ -2210,6 +2323,8 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call
2210 2323
2211void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid) 2324void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packet_cb *callback, uint8_t pktid)
2212{ 2325{
2326 assert(tox != nullptr);
2327
2213 if (pktid >= PACKET_ID_RANGE_LOSSY_START && pktid <= PACKET_ID_RANGE_LOSSY_END) { 2328 if (pktid >= PACKET_ID_RANGE_LOSSY_START && pktid <= PACKET_ID_RANGE_LOSSY_END) {
2214 tox->friend_lossy_packet_callback_per_pktid[pktid] = callback; 2329 tox->friend_lossy_packet_callback_per_pktid[pktid] = callback;
2215 } 2330 }
@@ -2218,6 +2333,8 @@ void tox_callback_friend_lossy_packet_per_pktid(Tox *tox, tox_friend_lossy_packe
2218bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, 2333bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
2219 Tox_Err_Friend_Custom_Packet *error) 2334 Tox_Err_Friend_Custom_Packet *error)
2220{ 2335{
2336 assert(tox != nullptr);
2337
2221 if (!data) { 2338 if (!data) {
2222 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); 2339 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
2223 return 0; 2340 return 0;
@@ -2243,6 +2360,8 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin
2243 2360
2244void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback) 2361void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback)
2245{ 2362{
2363 assert(tox != nullptr);
2364
2246 for (uint8_t i = PACKET_ID_RANGE_LOSSLESS_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END; ++i) { 2365 for (uint8_t i = PACKET_ID_RANGE_LOSSLESS_CUSTOM_START; i <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END; ++i) {
2247 tox->friend_lossless_packet_callback_per_pktid[i] = callback; 2366 tox->friend_lossless_packet_callback_per_pktid[i] = callback;
2248 } 2367 }
@@ -2250,6 +2369,8 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb
2250 2369
2251void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid) 2370void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless_packet_cb *callback, uint8_t pktid)
2252{ 2371{
2372 assert(tox != nullptr);
2373
2253 if ((pktid >= PACKET_ID_RANGE_LOSSLESS_CUSTOM_START && pktid <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END) 2374 if ((pktid >= PACKET_ID_RANGE_LOSSLESS_CUSTOM_START && pktid <= PACKET_ID_RANGE_LOSSLESS_CUSTOM_END)
2254 || pktid == PACKET_ID_MSI) { 2375 || pktid == PACKET_ID_MSI) {
2255 tox->friend_lossless_packet_callback_per_pktid[pktid] = callback; 2376 tox->friend_lossless_packet_callback_per_pktid[pktid] = callback;
@@ -2258,6 +2379,8 @@ void tox_callback_friend_lossless_packet_per_pktid(Tox *tox, tox_friend_lossless
2258 2379
2259void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) 2380void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
2260{ 2381{
2382 assert(tox != nullptr);
2383
2261 if (dht_id) { 2384 if (dht_id) {
2262 lock(tox); 2385 lock(tox);
2263 memcpy(dht_id, dht_get_self_public_key(tox->m->dht), CRYPTO_PUBLIC_KEY_SIZE); 2386 memcpy(dht_id, dht_get_self_public_key(tox->m->dht), CRYPTO_PUBLIC_KEY_SIZE);
@@ -2267,6 +2390,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
2267 2390
2268void tox_set_av_object(Tox *tox, void *object) 2391void tox_set_av_object(Tox *tox, void *object)
2269{ 2392{
2393 assert(tox != nullptr);
2270 lock(tox); 2394 lock(tox);
2271 tox->toxav_object = object; 2395 tox->toxav_object = object;
2272 unlock(tox); 2396 unlock(tox);
@@ -2274,6 +2398,7 @@ void tox_set_av_object(Tox *tox, void *object)
2274 2398
2275void *tox_get_av_object(const Tox *tox) 2399void *tox_get_av_object(const Tox *tox)
2276{ 2400{
2401 assert(tox != nullptr);
2277 lock(tox); 2402 lock(tox);
2278 void *object = tox->toxav_object; 2403 void *object = tox->toxav_object;
2279 unlock(tox); 2404 unlock(tox);
@@ -2282,6 +2407,7 @@ void *tox_get_av_object(const Tox *tox)
2282 2407
2283uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error) 2408uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
2284{ 2409{
2410 assert(tox != nullptr);
2285 lock(tox); 2411 lock(tox);
2286 const uint16_t port = net_htons(net_port(tox->m->net)); 2412 const uint16_t port = net_htons(net_port(tox->m->net));
2287 unlock(tox); 2413 unlock(tox);
@@ -2297,6 +2423,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
2297 2423
2298uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error) 2424uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error)
2299{ 2425{
2426 assert(tox != nullptr);
2300 lock(tox); 2427 lock(tox);
2301 2428
2302 if (tox->m->tcp_server) { 2429 if (tox->m->tcp_server) {