util: strndup really stop and add null termination

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-26 18:01:25 +02:00
parent c4d8cad1c5
commit c8bd181b27
1 changed files with 7 additions and 1 deletions

View File

@ -215,7 +215,13 @@ static inline
char * a_strndup(const char *s, ssize_t l) char * a_strndup(const char *s, ssize_t l)
{ {
ssize_t len = MIN(a_strlen(s), 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. /** \brief \c NULL resistant strcmp.