From 533d6dbf37d7a32ee339058f6657f64ba1009525 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 29 Apr 2006 14:34:50 +0000 Subject: [PATCH] Use strlcpy() --- src/network/getaddrinfo.c | 16 +++++----------- src/stream_output/sap.c | 3 +-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c index 872ce72312..afd4f27ebc 100644 --- a/src/network/getaddrinfo.c +++ b/src/network/getaddrinfo.c @@ -25,7 +25,7 @@ #include #include /* size_t */ -#include /* strncpy(), strlen(), memcpy(), memset(), strchr() */ +#include /* strlen(), memcpy(), memset(), strchr() */ #include /* malloc(), free(), strtoul() */ #include @@ -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; diff --git a/src/stream_output/sap.c b/src/stream_output/sap.c index 4a63b198bd..5a5f6535a8 100644 --- a/src/stream_output/sap.c +++ b/src/stream_output/sap.c @@ -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'; -- 2.39.2