X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=libiberty%2Fstrndup.c;h=a7ff3a9bbfc505d9da7ec7b50c119e4309fb6d25;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=9e9b4e2991f833082acd176f48825f76d5a888b9;hpb=01f0fe5e0450edf168c1f612feb93cf588e4e7ea;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/strndup.c b/libiberty/strndup.c index 9e9b4e2991..a7ff3a9bbf 100644 --- a/libiberty/strndup.c +++ b/libiberty/strndup.c @@ -1,5 +1,5 @@ /* Implement the strndup function. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005-2020 Free Software Foundation, Inc. Written by Kaveh R. Ghazi . This file is part of the libiberty library. @@ -33,7 +33,7 @@ memory was available. The result is always NUL terminated. #include "ansidecl.h" #include -extern size_t strlen (const char*); +extern size_t strnlen (const char *s, size_t maxlen); extern PTR malloc (size_t); extern PTR memcpy (PTR, const PTR, size_t); @@ -41,10 +41,7 @@ char * strndup (const char *s, size_t n) { char *result; - size_t len = strlen (s); - - if (n < len) - len = n; + size_t len = strnlen (s, n); result = (char *) malloc (len + 1); if (!result)