You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/10 16:54:03 UTC

[incubator-nuttx] branch master updated: net/local: unified formatting name function

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e146590a9 net/local: unified formatting name function
8e146590a9 is described below

commit 8e146590a9dccec39752f1d2ee094c87508d9635
Author: chao an <an...@xiaomi.com>
AuthorDate: Mon Oct 10 22:59:56 2022 +0800

    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 <an...@xiaomi.com>
---
 net/local/local_fifo.c | 64 ++++++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 33 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
@@ -56,31 +56,44 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: local_cs_name
+ * Name: local_format_name
  *
  * Description:
- *   Create the name of the client-to-server FIFO.
+ *   Format the name of the half duplex FIFO.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_NET_LOCAL_STREAM
-static inline void local_cs_name(FAR struct local_conn_s *conn,
-                                 FAR char *path)
+static void local_format_name(FAR const char *inpath, FAR char *outpath,
+                              FAR const char *suffix, int32_t id)
 {
-  if (conn->lc_instance_id < 0)
+  if (id < 0)
     {
-      snprintf(path, LOCAL_FULLPATH_LEN - 1,
-               CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_CS_SUFFIX,
-               conn->lc_path);
+      snprintf(outpath, LOCAL_FULLPATH_LEN - 1,
+               CONFIG_NET_LOCAL_VFS_PATH "/%s%s", inpath, suffix);
     }
   else
     {
-      snprintf(path, LOCAL_FULLPATH_LEN - 1,
-               CONFIG_NET_LOCAL_VFS_PATH "/%s" LOCAL_CS_SUFFIX "%" PRIx32,
-               conn->lc_path, conn->lc_instance_id);
+      snprintf(outpath, LOCAL_FULLPATH_LEN - 1,
+               CONFIG_NET_LOCAL_VFS_PATH "/%s%s%" PRIx32,
+               inpath, suffix, id);
     }
 
-  path[LOCAL_FULLPATH_LEN - 1] = '\0';
+  outpath[LOCAL_FULLPATH_LEN - 1] = '\0';
+}
+
+/****************************************************************************
+ * Name: local_cs_name
+ *
+ * Description:
+ *   Create the name of the client-to-server FIFO.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_LOCAL_STREAM
+static void local_cs_name(FAR struct local_conn_s *conn, FAR char *path)
+{
+  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 */