diff options
author | Jerzi Kaminsky <JerziKaminsky@users.noreply.github.com> | 2017-04-16 10:30:17 +0300 |
---|---|---|
committer | Jerzi Kaminsky <JerziKaminsky@users.noreply.github.com> | 2017-04-16 16:39:53 +0300 |
commit | eb3b1ec5f1ccdeccae237fa8c8662e795bb7fad7 (patch) | |
tree | 5dfa6984f5d64d1c63dfc402786f2023c7e33586 /common | |
parent | Merge pull request #1171 from JerziKaminsky/misc_fixes (diff) | |
download | sway-eb3b1ec5f1ccdeccae237fa8c8662e795bb7fad7.tar.gz sway-eb3b1ec5f1ccdeccae237fa8c8662e795bb7fad7.tar.zst sway-eb3b1ec5f1ccdeccae237fa8c8662e795bb7fad7.zip |
Fix variadic forwarding in sway_assert
_sway_assert is a variadic function which tries
to delegate to another variadic function. This
requires a vprintf-style variant of the delegate.
https://stackoverflow.com/a/150616
Diffstat (limited to 'common')
-rw-r--r-- | common/log.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/common/log.c b/common/log.c index c3809c69..23b756eb 100644 --- a/common/log.c +++ b/common/log.c | |||
@@ -63,7 +63,8 @@ void sway_abort(const char *format, ...) { | |||
63 | sway_terminate(EXIT_FAILURE); | 63 | sway_terminate(EXIT_FAILURE); |
64 | } | 64 | } |
65 | 65 | ||
66 | void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { | 66 | void _sway_vlog(const char *filename, int line, log_importance_t verbosity, |
67 | const char *format, va_list args) { | ||
67 | if (verbosity <= v) { | 68 | if (verbosity <= v) { |
68 | // prefix the time to the log message | 69 | // prefix the time to the log message |
69 | static struct tm result; | 70 | static struct tm result; |
@@ -99,10 +100,7 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const | |||
99 | fprintf(stderr, "[%s:%d] ", file, line); | 100 | fprintf(stderr, "[%s:%d] ", file, line); |
100 | } | 101 | } |
101 | 102 | ||
102 | va_list args; | ||
103 | va_start(args, format); | ||
104 | vfprintf(stderr, format, args); | 103 | vfprintf(stderr, format, args); |
105 | va_end(args); | ||
106 | 104 | ||
107 | if (colored && isatty(STDERR_FILENO)) { | 105 | if (colored && isatty(STDERR_FILENO)) { |
108 | fprintf(stderr, "\x1B[0m"); | 106 | fprintf(stderr, "\x1B[0m"); |
@@ -111,6 +109,13 @@ void _sway_log(const char *filename, int line, log_importance_t verbosity, const | |||
111 | } | 109 | } |
112 | } | 110 | } |
113 | 111 | ||
112 | void _sway_log(const char *filename, int line, log_importance_t verbosity, const char* format, ...) { | ||
113 | va_list args; | ||
114 | va_start(args, format); | ||
115 | _sway_vlog(filename, line, verbosity, format, args); | ||
116 | va_end(args); | ||
117 | } | ||
118 | |||
114 | void sway_log_errno(log_importance_t verbosity, char* format, ...) { | 119 | void sway_log_errno(log_importance_t verbosity, char* format, ...) { |
115 | if (verbosity <= v) { | 120 | if (verbosity <= v) { |
116 | unsigned int c = verbosity; | 121 | unsigned int c = verbosity; |
@@ -144,7 +149,7 @@ bool _sway_assert(bool condition, const char* format, ...) { | |||
144 | 149 | ||
145 | va_list args; | 150 | va_list args; |
146 | va_start(args, format); | 151 | va_start(args, format); |
147 | sway_log(L_ERROR, format, args); | 152 | sway_vlog(L_ERROR, format, args); |
148 | va_end(args); | 153 | va_end(args); |
149 | 154 | ||
150 | #ifndef NDEBUG | 155 | #ifndef NDEBUG |