summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-08-12 11:35:01 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-08-12 14:09:59 +0000
commitd92c96e7832ae4c7f9c32eec0d2f7f661a65b73e (patch)
treef7577121b3463ad094493fbb0cf3601fbcb0f9dc
parentf0f456398da65fc36837c0ab66b983a69b6f9e3e (diff)
Fix a few warnings from clang.
Also remove the use of a VLA in a context where there can be unbounded memory allocations.
-rw-r--r--auto_tests/conference_double_invite_test.c2
-rw-r--r--auto_tests/conference_simple_test.c7
-rw-r--r--other/analysis/gen-file.sh1
-rw-r--r--other/bootstrap_daemon/src/command_line_arguments.c14
-rw-r--r--other/bootstrap_daemon/src/log.h10
-rw-r--r--other/bootstrap_daemon/src/log_backend_stdout.h2
-rw-r--r--other/bootstrap_daemon/src/log_backend_syslog.c4
-rw-r--r--other/bootstrap_daemon/src/log_backend_syslog.h2
-rw-r--r--testing/DHT_test.c2
-rw-r--r--testing/Messenger_test.c6
10 files changed, 28 insertions, 22 deletions
diff --git a/auto_tests/conference_double_invite_test.c b/auto_tests/conference_double_invite_test.c
index 55aabfb6..026c2fcb 100644
--- a/auto_tests/conference_double_invite_test.c
+++ b/auto_tests/conference_double_invite_test.c
@@ -73,7 +73,7 @@ static void conference_double_invite_test(Tox **toxes, State *state)
73 fprintf(stderr, "Invitations accepted\n"); 73 fprintf(stderr, "Invitations accepted\n");
74 74
75 // Invite one more time, resulting in friend -1 inviting tox1 (toxes[1]). 75 // Invite one more time, resulting in friend -1 inviting tox1 (toxes[1]).
76 tox_conference_invite(toxes[0], 0, state[0].conference, 0); 76 tox_conference_invite(toxes[0], 0, state[0].conference, nullptr);
77 77
78 tox_iterate(toxes[0], &state[0]); 78 tox_iterate(toxes[0], &state[0]);
79 tox_iterate(toxes[1], &state[1]); 79 tox_iterate(toxes[1], &state[1]);
diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c
index f2bede30..5a286b4a 100644
--- a/auto_tests/conference_simple_test.c
+++ b/auto_tests/conference_simple_test.c
@@ -99,9 +99,10 @@ static void handle_conference_peer_list_changed(Tox *tox, uint32_t conference_nu
99 return; 99 return;
100 } 100 }
101 101
102 TOX_ERR_CONFERENCE_INVITE err; 102 TOX_ERR_CONFERENCE_INVITE err_invite;
103 tox_conference_invite(tox, 1, state->conference, &err); 103 tox_conference_invite(tox, 1, state->conference, &err_invite);
104 ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err); 104 ck_assert_msg(err_invite == TOX_ERR_CONFERENCE_INVITE_OK,
105 "tox2 failed to invite tox3: err = %d", err_invite);
105 106
106 state->invited_next = true; 107 state->invited_next = true;
107 fprintf(stderr, "tox2 invited tox3\n"); 108 fprintf(stderr, "tox2 invited tox3\n");
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh
index 8c320acf..019bd8f9 100644
--- a/other/analysis/gen-file.sh
+++ b/other/analysis/gen-file.sh
@@ -43,6 +43,7 @@ echo "#include <random>" >> amalgamation.cc
43put auto_tests/check_compat.h 43put auto_tests/check_compat.h
44 44
45FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'" 45FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'"
46FIND_QUERY="$FIND_QUERY -and -not -wholename './_build/*'"
46FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'" 47FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'"
47FIND_QUERY="$FIND_QUERY -and -not -wholename './toxav/*.cc'" 48FIND_QUERY="$FIND_QUERY -and -not -wholename './toxav/*.cc'"
48FIND_QUERY="$FIND_QUERY -and -not -wholename './toxcore/*.cc'" 49FIND_QUERY="$FIND_QUERY -and -not -wholename './toxcore/*.cc'"
diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c
index d9747932..d76bc655 100644
--- a/other/bootstrap_daemon/src/command_line_arguments.c
+++ b/other/bootstrap_daemon/src/command_line_arguments.c
@@ -73,13 +73,13 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
73 73
74 opterr = 0; 74 opterr = 0;
75 75
76 static struct option long_options[] = { 76 static const struct option long_options[] = {
77 {"config", required_argument, 0, 'c'}, // required option 77 {"config", required_argument, nullptr, 'c'}, // required option
78 {"foreground", no_argument, 0, 'f'}, 78 {"foreground", no_argument, nullptr, 'f'},
79 {"help", no_argument, 0, 'h'}, 79 {"help", no_argument, nullptr, 'h'},
80 {"log-backend", required_argument, 0, 'l'}, // optional, defaults to syslog 80 {"log-backend", required_argument, nullptr, 'l'}, // optional, defaults to syslog
81 {"version", no_argument, 0, 'v'}, 81 {"version", no_argument, nullptr, 'v'},
82 {0, 0, 0, 0 } 82 {nullptr, 0, nullptr, 0 }
83 }; 83 };
84 84
85 bool cfg_file_path_set = false; 85 bool cfg_file_path_set = false;
diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h
index ab7cd30b..a810d997 100644
--- a/other/bootstrap_daemon/src/log.h
+++ b/other/bootstrap_daemon/src/log.h
@@ -27,6 +27,8 @@
27 27
28#include <stdbool.h> 28#include <stdbool.h>
29 29
30#include "../../../toxcore/ccompat.h"
31
30typedef enum LOG_BACKEND { 32typedef enum LOG_BACKEND {
31 LOG_BACKEND_STDOUT, 33 LOG_BACKEND_STDOUT,
32 LOG_BACKEND_SYSLOG 34 LOG_BACKEND_SYSLOG
@@ -41,13 +43,13 @@ typedef enum LOG_LEVEL {
41/** 43/**
42 * Initializes logger. 44 * Initializes logger.
43 * @param backend Specifies which backend to use. 45 * @param backend Specifies which backend to use.
44 * @return true on success, flase if log is already opened. 46 * @return true on success, false if log is already opened.
45 */ 47 */
46bool log_open(LOG_BACKEND backend); 48bool log_open(LOG_BACKEND backend);
47 49
48/** 50/**
49 * Releases all used resources by the logger. 51 * Releases all used resources by the logger.
50 * @return true on success, flase if log is already closed. 52 * @return true on success, false if log is already closed.
51 */ 53 */
52bool log_close(void); 54bool log_close(void);
53 55
@@ -56,9 +58,9 @@ bool log_close(void);
56 * @param level Log level to use. 58 * @param level Log level to use.
57 * @param format printf-like format string. 59 * @param format printf-like format string.
58 * @param ... Zero or more arguments, similar to printf function. 60 * @param ... Zero or more arguments, similar to printf function.
59 * @return true on success, flase if log is closed. 61 * @return true on success, false if log is closed.
60 */ 62 */
61bool log_write(LOG_LEVEL level, const char *format, ...); 63bool log_write(LOG_LEVEL level, const char *format, ...) GNU_PRINTF(2, 3);
62 64
63 65
64#endif // LOG_H 66#endif // LOG_H
diff --git a/other/bootstrap_daemon/src/log_backend_stdout.h b/other/bootstrap_daemon/src/log_backend_stdout.h
index 5d8dd463..096af49c 100644
--- a/other/bootstrap_daemon/src/log_backend_stdout.h
+++ b/other/bootstrap_daemon/src/log_backend_stdout.h
@@ -29,6 +29,6 @@
29 29
30#include <stdarg.h> 30#include <stdarg.h>
31 31
32void log_backend_stdout_write(LOG_LEVEL level, const char *format, va_list args); 32void log_backend_stdout_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
33 33
34#endif // LOG_BACKEND_STDOUT_H 34#endif // LOG_BACKEND_STDOUT_H
diff --git a/other/bootstrap_daemon/src/log_backend_syslog.c b/other/bootstrap_daemon/src/log_backend_syslog.c
index 9fc6d18f..73ecc964 100644
--- a/other/bootstrap_daemon/src/log_backend_syslog.c
+++ b/other/bootstrap_daemon/src/log_backend_syslog.c
@@ -30,6 +30,7 @@
30 30
31#include <assert.h> 31#include <assert.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h>
33#include <syslog.h> 34#include <syslog.h>
34 35
35void log_backend_syslog_open(void) 36void log_backend_syslog_open(void)
@@ -72,8 +73,9 @@ void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args)
72 return; 73 return;
73 } 74 }
74 75
75 VLA(char, buf, size + 1); 76 char *buf = (char *)malloc(size + 1);
76 vsnprintf(buf, size + 1, format, args); 77 vsnprintf(buf, size + 1, format, args);
77 78
78 syslog(log_backend_syslog_level(level), "%s", buf); 79 syslog(log_backend_syslog_level(level), "%s", buf);
80 free(buf);
79} 81}
diff --git a/other/bootstrap_daemon/src/log_backend_syslog.h b/other/bootstrap_daemon/src/log_backend_syslog.h
index f09b0431..5e9a3069 100644
--- a/other/bootstrap_daemon/src/log_backend_syslog.h
+++ b/other/bootstrap_daemon/src/log_backend_syslog.h
@@ -31,6 +31,6 @@
31 31
32void log_backend_syslog_open(void); 32void log_backend_syslog_open(void);
33void log_backend_syslog_close(void); 33void log_backend_syslog_close(void);
34void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args); 34void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args) GNU_PRINTF(2, 0);
35 35
36#endif // LOG_BACKEND_SYSLOG_H 36#endif // LOG_BACKEND_SYSLOG_H
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 78853746..c9372847 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -215,7 +215,7 @@ int main(int argc, char *argv[])
215 } 215 }
216 216
217 uint8_t *bin_id = hex_string_to_bin(temp_id); 217 uint8_t *bin_id = hex_string_to_bin(temp_id);
218 dht_addfriend(dht, bin_id, 0, 0, 0, 0); 218 dht_addfriend(dht, bin_id, nullptr, nullptr, 0, nullptr);
219 free(bin_id); 219 free(bin_id);
220 220
221 perror("Initialization"); 221 perror("Initialization");
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index a3380a09..4c140da9 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -53,7 +53,7 @@ static void print_message(Messenger *m, uint32_t friendnumber, unsigned int type
53 void *userdata) 53 void *userdata)
54{ 54{
55 printf("Message with length %u received from %u: %s \n", (unsigned)length, friendnumber, string); 55 printf("Message with length %u received from %u: %s \n", (unsigned)length, friendnumber, string);
56 m_send_message_generic(m, friendnumber, type, (const uint8_t *)"Test1", 6, 0); 56 m_send_message_generic(m, friendnumber, type, (const uint8_t *)"Test1", 6, nullptr);
57} 57}
58 58
59/* TODO(irungentoo): needed as print_request has to match the interface expected by 59/* TODO(irungentoo): needed as print_request has to match the interface expected by
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
108 108
109 Messenger_Options options = {0}; 109 Messenger_Options options = {0};
110 options.ipv6enabled = ipv6enabled; 110 options.ipv6enabled = ipv6enabled;
111 m = new_messenger(&options, 0); 111 m = new_messenger(&options, nullptr);
112 112
113 if (!m) { 113 if (!m) {
114 fputs("Failed to allocate messenger datastructure\n", stderr); 114 fputs("Failed to allocate messenger datastructure\n", stderr);
@@ -181,7 +181,7 @@ int main(int argc, char *argv[])
181 getname(m, num, name); 181 getname(m, num, name);
182 printf("%s\n", name); 182 printf("%s\n", name);
183 183
184 m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, 0); 184 m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, nullptr);
185 do_messenger(m, nullptr); 185 do_messenger(m, nullptr);
186 c_sleep(30); 186 c_sleep(30);
187 FILE *file = fopen("Save.bak", "wb"); 187 FILE *file = fopen("Save.bak", "wb");