From 8e146590a9dccec39752f1d2ee094c87508d9635 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 10 Oct 2022 22:59:56 +0800 Subject: [PATCH] net/local: unified formatting name function fix build warning on GCC 12.2.0 In file included from local/local_fifo.c:25: In function 'local_hd_name', inlined from 'local_open_receiver' at local/local_fifo.c:593:3: local/local_fifo.c:128:12: warning: '%s' directive output may be truncated writing up to 107 bytes into a region of size 97 [-Wformat-truncation=] 128 | CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath); | ^~~~~~~~~~~~~~~~~~~~~~~~~ local/local_fifo.c: In function 'local_open_receiver': local/local_fifo.c:128:40: note: format string is defined here 128 | CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath); | ^~ In function 'local_hd_name', inlined from 'local_open_receiver' at local/local_fifo.c:593:3: local/local_fifo.c:127:3: note: 'snprintf' output between 15 and 122 bytes into a destination of size 109 127 | snprintf(outpath, LOCAL_FULLPATH_LEN - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 128 | CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: chao an --- net/local/local_fifo.c | 70 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 63f3dbcd34..9de6eae68b 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -55,6 +55,32 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: local_format_name + * + * Description: + * Format the name of the half duplex FIFO. + * + ****************************************************************************/ + +static void local_format_name(FAR const char *inpath, FAR char *outpath, + FAR const char *suffix, int32_t id) +{ + if (id < 0) + { + snprintf(outpath, LOCAL_FULLPATH_LEN - 1, + CONFIG_NET_LOCAL_VFS_PATH "/%s%s", inpath, suffix); + } + else + { + snprintf(outpath, LOCAL_FULLPATH_LEN - 1, + CONFIG_NET_LOCAL_VFS_PATH "/%s%s%" PRIx32, + inpath, suffix, id); + } + + outpath[LOCAL_FULLPATH_LEN - 1] = '\0'; +} + /**************************************************************************** * Name: local_cs_name * @@ -64,23 +90,10 @@ ****************************************************************************/ #ifdef CONFIG_NET_LOCAL_STREAM -static inline void local_cs_name(FAR struct local_conn_s *conn, - FAR char *path) +static void local_cs_name(FAR struct local_conn_s *conn, FAR char *path) { - if (conn->lc_instance_id < 0) - { - snprintf(path, LOCAL_FULLPATH_LEN - 1, - CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_CS_SUFFIX, - conn->lc_path); - } - else - { - snprintf(path, LOCAL_FULLPATH_LEN - 1, - CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_CS_SUFFIX "%" PRIx32, - conn->lc_path, conn->lc_instance_id); - } - - path[LOCAL_FULLPATH_LEN - 1] = '\0'; + local_format_name(conn->lc_path, path, + LOCAL_CS_SUFFIX, conn->lc_instance_id); } #endif /* CONFIG_NET_LOCAL_STREAM */ @@ -93,23 +106,10 @@ static inline void local_cs_name(FAR struct local_conn_s *conn, ****************************************************************************/ #ifdef CONFIG_NET_LOCAL_STREAM -static inline void local_sc_name(FAR struct local_conn_s *conn, - FAR char *path) +static void local_sc_name(FAR struct local_conn_s *conn, FAR char *path) { - if (conn->lc_instance_id < 0) - { - snprintf(path, LOCAL_FULLPATH_LEN - 1, - CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_SC_SUFFIX, - conn->lc_path); - } - else - { - snprintf(path, LOCAL_FULLPATH_LEN - 1, - CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_SC_SUFFIX "%" PRIx32, - conn->lc_path, conn->lc_instance_id); - } - - path[LOCAL_FULLPATH_LEN - 1] = '\0'; + local_format_name(conn->lc_path, path, + LOCAL_SC_SUFFIX, conn->lc_instance_id); } #endif /* CONFIG_NET_LOCAL_STREAM */ @@ -122,11 +122,9 @@ static inline void local_sc_name(FAR struct local_conn_s *conn, ****************************************************************************/ #ifdef CONFIG_NET_LOCAL_DGRAM -static inline void local_hd_name(FAR const char *inpath, FAR char *outpath) +static void local_hd_name(FAR const char *inpath, FAR char *outpath) { - snprintf(outpath, LOCAL_FULLPATH_LEN - 1, - CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_HD_SUFFIX, inpath); - outpath[LOCAL_FULLPATH_LEN - 1] = '\0'; + local_format_name(inpath, outpath, LOCAL_HD_SUFFIX, -1); } #endif /* CONFIG_NET_LOCAL_DGRAM */