From: Tom Hromatka Date: Tue, 29 Jul 2025 16:04:41 +0000 (+0000) Subject: api: Fix clang warning X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=80f12b0429f87a0df3251b8ff8074fb3828519df;p=thirdparty%2Flibcgroup.git api: Fix clang warning Fix the following warnings from clang by reducing the size passed to strncat by 1 as recommended by clang. api.c:3727:22: warning: the value of the size argument in 'strncat' is too large, might lead to a buffer overflow [-Wstrncat-size] 3727 | strncat(path, file, sizeof(path) - strlen(path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ api.c:3727:22: note: change the argument to be the free space in the destination buffer minus the terminating null byte 3727 | strncat(path, file, sizeof(path) - strlen(path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ | sizeof(path) - strlen(path) - 1 Signed-off-by: Tom Hromatka Signed-off-by: Kamalesh Babulal --- diff --git a/src/api.c b/src/api.c index 0a9f847a..435d3679 100644 --- a/src/api.c +++ b/src/api.c @@ -3724,7 +3724,7 @@ static int cg_rd_ctrl_file(const char *subsys, const char *cgrp, const char *fil if (!cg_build_path_locked(cgrp, path, subsys)) return ECGFAIL; - strncat(path, file, sizeof(path) - strlen(path)); + strncat(path, file, sizeof(path) - strlen(path) - 1); ctrl_file = fopen(path, "re"); if (!ctrl_file) return ECGROUPVALUENOTEXIST;