diff options
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/ChangeLog | 8 | ||||
-rw-r--r-- | libiberty/strndup.c | 7 | ||||
-rw-r--r-- | libiberty/xstrndup.c | 5 |
3 files changed, 11 insertions, 9 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 42164c4..f0959c9 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,11 @@ +2016-11-30 David Malcolm <dmalcolm@redhat.com> + + PR c/78498 + * strndup.c (strlen): Delete decl. + (strnlen): Add decl. + (strndup): Call strnlen rather than strlen. + * xstrndup.c (xstrndup): Likewise. + 2016-11-29 Nathan Sidwell <nathan@acm.org> * cp-demangle.c (d_print_comp_inner): Fix parameter indentation. diff --git a/libiberty/strndup.c b/libiberty/strndup.c index 9e9b4e2..4556b96 100644 --- a/libiberty/strndup.c +++ b/libiberty/strndup.c @@ -33,7 +33,7 @@ memory was available. The result is always NUL terminated. #include "ansidecl.h" #include <stddef.h> -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) diff --git a/libiberty/xstrndup.c b/libiberty/xstrndup.c index 0a41f60..c3d2d83 100644 --- a/libiberty/xstrndup.c +++ b/libiberty/xstrndup.c @@ -48,10 +48,7 @@ char * xstrndup (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 = XNEWVEC (char, len + 1); |