diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-09-10 15:03:19 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2021-09-10 15:03:19 +0000 |
commit | 84fd3cd192c1aabcf4a16e1946404c599c934d4f (patch) | |
tree | 17c48c1a86a2df376f4c79d3dc119d9eaf25b0f5 /usr.bin | |
parent | 29c31bff197d38bab520e72aaeccf91ded3db3b2 (diff) |
Do fatal/fatalx a different way so the compiler trick to avoid warnings
becomes unnecessary, prompted by theo.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/log.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 16 |
2 files changed, 19 insertions, 34 deletions
diff --git a/usr.bin/tmux/log.c b/usr.bin/tmux/log.c index 2784db6e716..41e6629c9c0 100644 --- a/usr.bin/tmux/log.c +++ b/usr.bin/tmux/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.29 2021/09/10 14:22:24 nicm Exp $ */ +/* $OpenBSD: log.c,v 1.30 2021/09/10 15:03:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -99,28 +99,27 @@ log_close(void) /* Write a log message. */ static void printflike(1, 0) -log_vwrite(const char *msg, va_list ap) +log_vwrite(const char *msg, va_list ap, const char *prefix) { - char *fmt, *out; + char *s, *out; struct timeval tv; if (log_file == NULL) return; - if (vasprintf(&fmt, msg, ap) == -1) + if (vasprintf(&s, msg, ap) == -1) return; - if (stravis(&out, fmt, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) { - free(fmt); + if (stravis(&out, s, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) { + free(s); return; } + free(s); gettimeofday(&tv, NULL); - if (fprintf(log_file, "%lld.%06d %s\n", (long long)tv.tv_sec, - (int)tv.tv_usec, out) != -1) + if (fprintf(log_file, "%lld.%06d %s%s\n", (long long)tv.tv_sec, + (int)tv.tv_usec, prefix, out) != -1) fflush(log_file); - free(out); - free(fmt); } /* Log a debug message. */ @@ -133,7 +132,7 @@ log_debug(const char *msg, ...) return; va_start(ap, msg); - log_vwrite(msg, ap); + log_vwrite(msg, ap, ""); va_end(ap); } @@ -141,14 +140,16 @@ log_debug(const char *msg, ...) __dead void fatal(const char *msg, ...) { - char *fmt; + char tmp[256]; va_list ap; + if (snprintf(tmp, sizeof tmp, "fatal: %s: ", strerror(errno)) < 0) + exit (1); + va_start(ap, msg); - if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1) - exit(1); - no_format_nonliteral(log_vwrite(fmt, ap)); + log_vwrite(msg, ap, tmp); va_end(ap); + exit(1); } @@ -156,13 +157,11 @@ fatal(const char *msg, ...) __dead void fatalx(const char *msg, ...) { - char *fmt; va_list ap; va_start(ap, msg); - if (asprintf(&fmt, "fatal: %s", msg) == -1) - exit(1); - no_format_nonliteral(log_vwrite(fmt, ap)); + log_vwrite(msg, ap, "fatal: "); va_end(ap); + exit(1); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 0f43de41428..b47722682bf 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1141 2021/09/10 14:22:24 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1142 2021/09/10 15:03:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -93,20 +93,6 @@ struct winlink; #define DEFAULT_XPIXEL 16 #define DEFAULT_YPIXEL 32 -/* Don't complain about format arguments. */ -#if __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#define no_format_nonliteral(x) do { \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wformat-nonliteral\"") \ - x; \ - _Pragma ("GCC diagnostic pop") \ -} while (0) -#else -#define no_format_nonliteral(x) do { \ - x; \ -} while (0) -#endif - /* Attribute to make GCC check printf-like arguments. */ #define printflike(a, b) __attribute__ ((format (printf, a, b))) |