Guard against 'current_directory == NULL' on gdb_abspath (PR gdb/23613)
[deliverable/binutils-gdb.git] / libiberty / xstrndup.c
index 0a41f608ec0b9c71ddebc4975c688c88bdde30a3..bb0b512dce58ccd8c1f8c4ff163cba2b9212d37a 100644 (file)
@@ -1,5 +1,5 @@
 /* Implement the xstrndup function.
-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005-2019 Free Software Foundation, Inc.
    Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
 
 This file is part of the libiberty library.
@@ -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);
 
This page took 0.024118 seconds and 4 git commands to generate.