]> git.sesse.net Git - vlc/commitdiff
Use strlcpy()
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 14:34:50 +0000 (14:34 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 29 Apr 2006 14:34:50 +0000 (14:34 +0000)
src/network/getaddrinfo.c
src/stream_output/sap.c

index 872ce7231218ecde3fe82d4f2cc93d2a367d6eb8..afd4f27ebc8ca6bfbfce77dd67565cfddd6caeee 100644 (file)
@@ -25,7 +25,7 @@
 #include <vlc/vlc.h>
 
 #include <stddef.h> /* size_t */
-#include <string.h> /* strncpy(), strlen(), memcpy(), memset(), strchr() */
+#include <string.h> /* strlen(), memcpy(), memset(), strchr() */
 #include <stdlib.h> /* malloc(), free(), strtoul() */
 #include <errno.h>
 
@@ -175,8 +175,7 @@ __getnameinfo( const struct sockaddr *sa, socklen_t salen,
 
                 if (hent != NULL)
                 {
-                    strncpy (host, hent->h_name, hostlen);
-                    host[hostlen - 1] = '\0';
+                    strlcpy (host, hent->h_name, hostlen);
 
                     /*
                      * only keep first part of hostname
@@ -199,11 +198,8 @@ __getnameinfo( const struct sockaddr *sa, socklen_t salen,
             }
 
             if (!solved)
-            {
                 /* inet_ntoa() can't fail */
-                strncpy (host, inet_ntoa (addr->sin_addr), hostlen);
-                host[hostlen - 1] = '\0';
-            }
+                strlcpy (host, inet_ntoa (addr->sin_addr), hostlen);
         }
 
         if (serv != NULL)
@@ -222,8 +218,7 @@ __getnameinfo( const struct sockaddr *sa, socklen_t salen,
                                      ? "udp" : "tcp");
                 if (sent != NULL)
                 {
-                    strncpy (serv, sent->s_name, servlen);
-                    serv[servlen - 1] = 0;
+                    strlcpy (serv, sent->s_name, servlen);
                     solved = 1;
                 }
             }
@@ -636,8 +631,7 @@ int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
     }
     else
     {
-        strncpy( psz_buf, node, NI_MAXHOST );
-        psz_buf[NI_MAXHOST - 1] = '\0';
+        strlcpy( psz_buf, node, NI_MAXHOST );
 
         psz_node = psz_buf;
 
index 4a63b198bd44e892b22c093367ff4f7d25f57518..5a5f6535a895b55478eacea083c2bc7f14304568 100644 (file)
@@ -602,8 +602,7 @@ static char *SDPGenerate( sap_handler_t *p_sap,
     {
         char *ptr;
 
-        strncpy( psz_uribuf, p_session->psz_uri + 1, sizeof( psz_uribuf ) );
-        psz_uribuf[sizeof( psz_uribuf ) - 1] = '\0';
+        strlcpy( psz_uribuf, p_session->psz_uri + 1, sizeof( psz_uribuf ) );
         ptr = strchr( psz_uribuf, '%' );
         if( ptr != NULL)
             *ptr = '\0';