misc: sprintf be gone
[vpp.git] / src / plugins / hs_apps / vcl / sock_test_client.c
index ea89987..6f5fb07 100644 (file)
@@ -211,8 +211,8 @@ echo_test_client ()
                                nbytes, &tsock->stats);
              if (rx_bytes > 0)
                {
-                 printf ("CLIENT (fd %d): RX (%d bytes) - '%s'\n",
-                         tsock->fd, rx_bytes, tsock->rxbuf);
+                 printf ("CLIENT (fd %d): RX (%d bytes)\n", tsock->fd,
+                         rx_bytes);
 
                  if (tsock->stats.rx_bytes != tsock->stats.tx_bytes)
                    printf ("CLIENT: WARNING: bytes read (%lu) "
@@ -327,7 +327,7 @@ echo_test_client ()
        {
          static char buf[64];
 
-         sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
+         snprintf (buf, sizeof (buf), "CLIENT (fd %d) RESULTS", tsock->fd);
          vcl_test_stats_dump (buf, &tsock->stats,
                               1 /* show_rx */ , 1 /* show tx */ ,
                               ctrl->cfg.verbose);
@@ -498,7 +498,7 @@ stream_test_client (vcl_test_t test)
        {
          static char buf[64];
 
-         sprintf (buf, "CLIENT (fd %d) RESULTS", tsock->fd);
+         snprintf (buf, sizeof (buf), "CLIENT (fd %d) RESULTS", tsock->fd);
          vcl_test_stats_dump (buf, &tsock->stats,
                               test == VCL_TEST_TYPE_BI /* show_rx */ ,
                               1 /* show tx */ , ctrl->cfg.verbose);
@@ -620,8 +620,9 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
          return -1;
        }
 
-      if (!scm->test_socket)
-       memset (tsock, 0, sizeof (*tsock));
+      memset (&tsock[scm->num_test_sockets], 0,
+             sizeof (vcl_test_session_t) * (num_test_sockets -
+                                            scm->num_test_sockets));
 
       scm->test_socket = tsock;
       for (i = scm->num_test_sockets; i < num_test_sockets; i++)
@@ -650,14 +651,6 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
                       errno_val);
              return tsock->fd;
            }
-         if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0)
-           {
-             errno_val = errno;
-             perror ("ERROR in sock_test_connect_test_sockets()");
-             fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n",
-                      errno_val);
-             return -1;
-           }
 
 #ifdef VCL_TEST
          rv = vppcom_session_connect (tsock->fd, &scm->server_endpt);
@@ -667,9 +660,8 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
              rv = -1;
            }
 #else
-         rv =
-           connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
-                    scm->server_addr_size);
+         rv = connect (tsock->fd, (struct sockaddr *) &scm->server_addr,
+                       scm->server_addr_size);
 #endif
          if (rv < 0)
            {
@@ -679,6 +671,14 @@ sock_test_connect_test_sockets (uint32_t num_test_sockets)
                       "(errno = %d)!\n", errno_val);
              return -1;
            }
+         if (fcntl (tsock->fd, F_SETFL, O_NONBLOCK) < 0)
+           {
+             errno_val = errno;
+             perror ("ERROR in sock_test_connect_test_sockets()");
+             fprintf (stderr, "CLIENT: ERROR: fcntl failed (errno = %d)!\n",
+                      errno_val);
+             return -1;
+           }
          tsock->cfg = ctrl->cfg;
          vcl_test_session_buf_alloc (tsock);
          sock_test_cfg_sync (tsock);