From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 4C80F4696C0 for ; Thu, 28 Nov 2019 00:30:39 +0300 (MSK) Received: by smtp5.mail.ru with esmtpa (envelope-from ) id 1ia4tS-0007Ph-Jr for tarantool-patches@dev.tarantool.org; Thu, 28 Nov 2019 00:30:38 +0300 From: Chris Sosnin Date: Thu, 28 Nov 2019 00:30:37 +0300 Message-Id: <20191127213037.94837-2-k.sosnin@tarantool.org> In-Reply-To: <20191127213037.94837-1-k.sosnin@tarantool.org> References: <20191127213037.94837-1-k.sosnin@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2] build: GCC warning on strncpy List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Thank you for the review! See second version below. branch: https://github.com/tarantool/tarantool/tree/ksosnin/gh-4515-build-warning issue: https://github.com/tarantool/tarantool/issues/4515 As long as we are sure, that strlen(sd_unix_path) < sizeof(sa.sun_path) we can assume that there is always enough space and the path will be null-terminated. Thus, copy 1 byte less to get rid of the warning. Closes #4515 --- src/systemd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/systemd.c b/src/systemd.c index 6686c3ce0..c80259f06 100644 --- a/src/systemd.c +++ b/src/systemd.c @@ -67,7 +67,7 @@ int systemd_init() { .sun_path = { '\0' } }; if (strlen(sd_unix_path) >= sizeof(sa.sun_path)) { - say_error("systemd: NOTIFY_SOCKET is longer that MAX_UNIX_PATH"); + say_error("systemd: NOTIFY_SOCKET is longer than MAX_UNIX_PATH"); goto error; } if ((systemd_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { @@ -117,7 +117,7 @@ int systemd_notify(const char *message) { .sun_family = AF_UNIX, }; - strncpy(sa.sun_path, sd_unix_path, sizeof(sa.sun_path)); + strncpy(sa.sun_path, sd_unix_path, sizeof(sa.sun_path) - 1); if (sa.sun_path[0] == '@') sa.sun_path[0] = '\0'; -- 2.21.0 (Apple Git-122.2)