summaryrefslogtreecommitdiff
path: root/other
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 /other
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.
Diffstat (limited to 'other')
-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
6 files changed, 19 insertions, 14 deletions
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