From 552739fa20321c567067e5a5d502651ec843d314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 7 Jan 2019 18:30:30 +0100 Subject: [PATCH] module/i3: fix gcc warning Gcc (correctly) figured out that we may end up truncating the socket path. In practice, it's something that should never happen. Never the less, silence the warning by writing the socket path directly into the sockaddr_un object. --- modules/i3.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/i3.c b/modules/i3.c index 3acc9ba..6654cda 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -353,7 +353,7 @@ run(struct module_run_context *ctx) { struct private *m = ctx->module->private; - char sock_path[1024]; + struct sockaddr_un addr = {.sun_family = AF_UNIX}; { FILE *out = popen("i3 --get-socketpath", "r"); if (out == NULL) { @@ -362,13 +362,13 @@ run(struct module_run_context *ctx) return 1; } - fgets(sock_path, sizeof(sock_path), out); + fgets(addr.sun_path, sizeof(addr.sun_path), out); pclose(out); /* Strip newline */ - ssize_t len = strlen(sock_path); - if (sock_path[len - 1] == '\n') - sock_path[len - 1] = '\0'; + ssize_t len = strlen(addr.sun_path); + if (addr.sun_path[len - 1] == '\n') + addr.sun_path[len - 1] = '\0'; } int sock = socket(AF_UNIX, SOCK_STREAM, 0); @@ -378,9 +378,6 @@ run(struct module_run_context *ctx) return 1; } - struct sockaddr_un addr = {.sun_family = AF_UNIX}; - strncpy(addr.sun_path, sock_path, sizeof(addr.sun_path) - 1); - int r = connect(sock, (const struct sockaddr *)&addr, sizeof(addr)); if (r == -1) { LOG_ERRNO("failed to connect to i3 socket");