From c8bd181b27cd9b418776317deb2e420fa116127e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 26 Aug 2008 18:01:25 +0200 Subject: [PATCH] util: strndup really stop and add null termination Signed-off-by: Julien Danjou --- common/util.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/common/util.h b/common/util.h index be693c93..670a6ca0 100644 --- a/common/util.h +++ b/common/util.h @@ -215,7 +215,13 @@ static inline char * a_strndup(const char *s, ssize_t l) { ssize_t len = MIN(a_strlen(s), l); - return len ? p_dup(s, len + 1) : NULL; + if(len) + { + char *p = p_dup(s, len + 1); + p[len] = '\0'; + return p; + } + return NULL; } /** \brief \c NULL resistant strcmp.