diff options
-rw-r--r-- | minecctl/minecctl.c | 8 | ||||
-rw-r--r-- | minecproxy/idle.c | 2 | ||||
-rw-r--r-- | minecproxy/igmp.c | 12 | ||||
-rw-r--r-- | minecproxy/main.c | 14 | ||||
-rw-r--r-- | minecproxy/main.h | 2 | ||||
-rw-r--r-- | minecproxy/server-config.c | 2 | ||||
-rw-r--r-- | minecproxy/server-rcon.c | 2 | ||||
-rw-r--r-- | minecproxy/signal-handler.c | 2 | ||||
-rw-r--r-- | shared/config-parser.c | 4 | ||||
-rw-r--r-- | shared/debug.h | 6 | ||||
-rw-r--r-- | shared/external.h | 21 | ||||
-rw-r--r-- | shared/utils.h | 32 |
12 files changed, 67 insertions, 40 deletions
diff --git a/minecctl/minecctl.c b/minecctl/minecctl.c index bbc5d47..6f3133d 100644 --- a/minecctl/minecctl.c +++ b/minecctl/minecctl.c @@ -15,7 +15,7 @@ #include "server-config-options.h" void -__debug(enum debug_lvl lvl, const char *fmt, ...) +__debug(_unused_ enum debug_lvl lvl, const char *fmt, ...) { va_list ap; @@ -24,7 +24,7 @@ __debug(enum debug_lvl lvl, const char *fmt, ...) va_end(ap); } -__attribute__((noreturn)) void +_noreturn_ void __die(const char *fmt, ...) { va_list ap; @@ -108,7 +108,7 @@ static void read_packet(int sfd, char *buf, size_t len, int32_t *id, int32_t *type, const char **msg) { size_t off = 0; - size_t r; + ssize_t r; const char *error; while (true) { @@ -139,7 +139,7 @@ static void send_msg(int sfd, char *buf, size_t len, enum rcon_packet_type type, const char *msg, enum rcon_packet_type *rtype, const char **reply) { - static unsigned rcon_packet_id = 1; + static uint32_t rcon_packet_id = 1; size_t plen; int32_t id; diff --git a/minecproxy/idle.c b/minecproxy/idle.c index 79c7bab..90d7210 100644 --- a/minecproxy/idle.c +++ b/minecproxy/idle.c @@ -115,7 +115,7 @@ write_cmd(char **pos, const char *begin, const char *end) } static int -idle_check_handshake_complete(struct uring_task *task, int res) +idle_check_handshake_complete(struct uring_task *task, _unused_ int res) { size_t remain; char *pos; diff --git a/minecproxy/igmp.c b/minecproxy/igmp.c index dc43a9f..f1d380d 100644 --- a/minecproxy/igmp.c +++ b/minecproxy/igmp.c @@ -26,7 +26,7 @@ struct igmp { #define IPV4_MIN_HDR_LEN 20 #define IGMP_MIN_LEN 8 -struct __attribute__((packed, scalar_storage_order("big-endian"))) ipv4_hdr { +struct _big_endian_ ipv4_hdr { unsigned version:4; unsigned ihl:4; unsigned dscp:6; @@ -52,20 +52,20 @@ enum igmp_type { }; union igmp_msg { - struct __attribute__((packed, scalar_storage_order("big-endian"))) { + struct _big_endian_ { enum igmp_type type:8; unsigned unknown:8; unsigned checksum:16; } common; - struct __attribute__((packed, scalar_storage_order("big-endian"))) { + struct _big_endian_ { enum igmp_type type:8; unsigned resptime:8; unsigned checksum:16; unsigned addr:32; } v2; - struct __attribute__((packed, scalar_storage_order("big-endian"))) { + struct _big_endian_ { enum igmp_type type:8; unsigned reserved1:8; unsigned checksum:16; @@ -83,7 +83,7 @@ enum igmp_v3_record_type { }; union igmp_v3_record { - struct __attribute__((packed, scalar_storage_order("big-endian"))) { + struct _big_endian_ { enum igmp_v3_record_type type:8; unsigned auxlen:8; unsigned nsrcs:16; @@ -227,7 +227,7 @@ igmp_parse(struct igmp *igmp) switch (igmp_msg->common.type) { case IGMP_V1_MEMBERSHIP_REPORT: debug(DBG_IGMP, "igmp_v1_membership_report"); - /* fall through */ + _fallthrough_; case IGMP_V2_MEMBERSHIP_REPORT: { struct in_addr src; diff --git a/minecproxy/main.c b/minecproxy/main.c index 9a57aa8..8513766 100644 --- a/minecproxy/main.c +++ b/minecproxy/main.c @@ -156,7 +156,7 @@ __debug(enum debug_lvl lvl, const char *fmt, ...) va_end(ap); } -__attribute__((noreturn)) void +_noreturn_ void __die(const char *fmt, ...) { va_list ap; @@ -418,8 +418,8 @@ const struct { } }; -__attribute__((noreturn)) static void -usage(int argc, char **argv, bool invalid) +_noreturn_ static void +usage(char **argv, bool invalid) { if (invalid) info("Invalid option(s)"); @@ -548,23 +548,23 @@ cfg_init(int argc, char **argv) } if (!debug_category_str[i].name) - usage(argc, argv, true); + usage(argv, true); debug_mask |= DBG_VERBOSE; debug_mask |= debug_category_str[i].val; break; case 'h': - usage(argc, argv, false); + usage(argv, false); default: - usage(argc, argv, true); + usage(argv, true); } } if (optind < argc) - usage(argc, argv, true); + usage(argv, true); } static void diff --git a/minecproxy/main.h b/minecproxy/main.h index f1f5df2..8c8add0 100644 --- a/minecproxy/main.h +++ b/minecproxy/main.h @@ -51,7 +51,7 @@ struct uring_task_buf { struct uring_task { const char *name; - unsigned refcount; + int refcount; /* signed to catch refcount bugs */ int fd; struct uring_task *parent; void (*free)(struct uring_task *); diff --git a/minecproxy/server-config.c b/minecproxy/server-config.c index 5d8c724..8786f88 100644 --- a/minecproxy/server-config.c +++ b/minecproxy/server-config.c @@ -325,7 +325,7 @@ scfg_valid_filename(const char *name) struct server_cfg_monitor { struct uring_task task; - char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event)))); + char buf[4096] _alignas_(struct inotify_event); }; static void diff --git a/minecproxy/server-rcon.c b/minecproxy/server-rcon.c index 1f8ef70..b19bdb1 100644 --- a/minecproxy/server-rcon.c +++ b/minecproxy/server-rcon.c @@ -17,7 +17,7 @@ #include "rcon-protocol.h" static int -rcon_packet_complete(struct uring_task *task, int res) +rcon_packet_complete(struct uring_task *task, _unused_ int res) { assert_return(task, -EINVAL); assert_task_alive_or(DBG_RCON, task, return -EINTR); diff --git a/minecproxy/signal-handler.c b/minecproxy/signal-handler.c index 0173bf8..15c3816 100644 --- a/minecproxy/signal-handler.c +++ b/minecproxy/signal-handler.c @@ -110,7 +110,7 @@ out: } static void -hack_signal_handler(int signum, siginfo_t *si, void *ucontext) +hack_signal_handler(int signum, siginfo_t *si, _unused_ void *ucontext) { ssize_t r; diff --git a/shared/config-parser.c b/shared/config-parser.c index 8094cda..9f294f4 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -387,7 +387,7 @@ config_parse_line(const char *filename, char **buf, case CFG_VAL_TYPE_ASYNC_ADDRS: error("CFG_VAL_TYPE_ASYNC_ADDRS is a return value"); - /* Fall through */ + _fallthrough_; case CFG_VAL_TYPE_ADDRS: if (!strtosockaddrs(tmp, rvalue, async_dns)) @@ -433,7 +433,7 @@ config_parse_line(const char *filename, char **buf, break; case CFG_VAL_TYPE_INVALID: - /* fall through */ + _fallthrough_; default: goto error; } diff --git a/shared/debug.h b/shared/debug.h index 8581a9a..6f1a054 100644 --- a/shared/debug.h +++ b/shared/debug.h @@ -1,6 +1,7 @@ #ifndef foodebughfoo #define foodebughfoo +/* FIXME: Should these be shared? */ enum debug_lvl { DBG_ERROR = (0x1 << 1), DBG_INFO = (0x1 << 2), @@ -27,11 +28,6 @@ debug_enabled(enum debug_lvl lvl) return !!(lvl & debug_mask); } -/* These need to be defined in the linking binary */ -void __debug(enum debug_lvl lvl, const char *fmt, ...) __attribute__((format(printf, 2, 3))); - -void __die(const char *fmt, ...) __attribute__((format(printf, 1, 2))); - #define __ifdebug(lvl, fmt, ...) \ do { \ if (debug_enabled((lvl))) \ diff --git a/shared/external.h b/shared/external.h new file mode 100644 index 0000000..1d7f3b7 --- /dev/null +++ b/shared/external.h @@ -0,0 +1,21 @@ +#ifndef fooexternalhfoo +#define fooexternalhfoo + +/* These need to be defined in the linking binary */ +#define zmalloc(s) __zmalloc(__func__, __LINE__, s) +void *__zmalloc(const char *fn, int line, size_t s); + +#define xstrdup(s) __xstrdup(__func__, __LINE__, s) +char *__xstrdup(const char *fn, int line, const char *s); + +#define xstrndup(s, n) __xstrndup(__func__, __LINE__, s, n) +char *__xstrndup(const char *fn, int line, const char *s, size_t n); + +#define xfree(s) __xfree(__func__, __LINE__, s) +void __xfree(const char *fn, int line, void *ptr); + +void __debug(enum debug_lvl lvl, const char *fmt, ...) _printf_(2, 3); + +void __die(const char *fmt, ...) _printf_(1, 2); + +#endif diff --git a/shared/utils.h b/shared/utils.h index 3ad603b..0fc1429 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -12,21 +12,31 @@ extern unsigned debug_mask; -#include "list.h" -#include "debug.h" +#define _unused_ __attribute__((__unused__)) + +#define _printf_(a, b) __attribute__((__format__(printf, a, b))) -/* These functions need to be defined in the linking binary */ -#define zmalloc(s) __zmalloc(__func__, __LINE__, s) -void *__zmalloc(const char *fn, int line, size_t s); +#define _alignas_(x) __attribute__((__aligned__(__alignof(x)))) -#define xstrdup(s) __xstrdup(__func__, __LINE__, s) -char *__xstrdup(const char *fn, int line, const char *s); +#define _big_endian_ __attribute__((packed, scalar_storage_order("big-endian"))) -#define xstrndup(s, n) __xstrndup(__func__, __LINE__, s, n) -char *__xstrndup(const char *fn, int line, const char *s, size_t n); +#if __GNUC__ >= 7 +#define _fallthrough_ __attribute__((__fallthrough__)) +#else +#define _fallthrough_ +#endif -#define xfree(s) __xfree(__func__, __LINE__, s) -void __xfree(const char *fn, int line, void *ptr); +#ifndef _noreturn_ +#if __STDC_VERSION__ >= 201112L +#define _noreturn_ _Noreturn +#else +#define _noreturn_ __attribute__((__noreturn__)) +#endif +#endif + +#include "list.h" +#include "debug.h" +#include "external.h" /* Length of longest DNS name = 253 + trailing dot */ #define FQDN_STR_LEN 254 |