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/01/21 04:30:46 UTC

[incubator-nuttx-apps] branch master updated: netutils/netcat: fixed ISO C89/C90 related warnings: warning: ISO C90 forbids variable length array ‘buf’ [-Wvla] warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]

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-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a697c1  netutils/netcat: fixed ISO C89/C90 related warnings: warning: ISO C90 forbids variable length array ‘buf’ [-Wvla] warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
5a697c1 is described below

commit 5a697c18ba1fb750d8a9420bb74d28afd14d0ff5
Author: Alexander Lunev <al...@mail.ru>
AuthorDate: Thu Jan 20 23:24:18 2022 +0300

    netutils/netcat: fixed ISO C89/C90 related warnings:
    warning: ISO C90 forbids variable length array ‘buf’ [-Wvla]
    warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
---
 netutils/netcat/netcat_main.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/netutils/netcat/netcat_main.c b/netutils/netcat/netcat_main.c
index da32011..caa1609 100644
--- a/netutils/netcat/netcat_main.c
+++ b/netutils/netcat/netcat_main.c
@@ -44,18 +44,23 @@
 # define NETCAT_PORT 31337
 #endif
 
+#ifndef NETCAT_IOBUF_SIZE
+# define NETCAT_IOBUF_SIZE 256
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 int do_io(int infd, int outfd)
 {
-  size_t capacity = 256;
-  char buf[capacity];
+  ssize_t avail;
+  ssize_t written;
+  char buf[NETCAT_IOBUF_SIZE];
 
   while (true)
     {
-      ssize_t avail = read(infd, buf, capacity);
+      avail = read(infd, buf, NETCAT_IOBUF_SIZE);
       if (avail == 0)
         {
           break;
@@ -67,7 +72,7 @@ int do_io(int infd, int outfd)
           return 5;
         }
 
-      ssize_t written = write(outfd, buf, avail);
+      written = write(outfd, buf, avail);
       if (written == -1)
         {
           perror("do_io: write error");
@@ -113,6 +118,8 @@ int netcat_server(int argc, char * argv[])
   struct sockaddr_in client;
   int port = NETCAT_PORT;
   int result = EXIT_SUCCESS;
+  int conn;
+  socklen_t addrlen;
 
   if ((1 < argc) && (0 == strcmp("-l", argv[1])))
     {
@@ -160,8 +167,6 @@ int netcat_server(int argc, char * argv[])
       goto out;
     }
 
-  socklen_t addrlen;
-  int conn;
   if ((conn = accept(id, (struct sockaddr *)&client, &addrlen)) != -1)
     {
       result = do_io(conn, outfd);
@@ -195,6 +200,7 @@ int netcat_client(int argc, char * argv[])
   char *host = "127.0.0.1";
   int port = NETCAT_PORT;
   int result = EXIT_SUCCESS;
+  struct sockaddr_in server;
 #ifdef CONFIG_NETUTILS_NETCAT_SENDFILE
   struct stat stat_buf;
 #endif
@@ -239,7 +245,6 @@ int netcat_client(int argc, char * argv[])
       goto out;
     }
 
-  struct sockaddr_in server;
   server.sin_family = AF_INET;
   server.sin_port = htons(port);
   if (1 != inet_pton(AF_INET, host, &server.sin_addr))