libctf: avoid strndup
authorNick Alcock <nick.alcock@oracle.com>
Thu, 6 Jun 2019 13:10:08 +0000 (14:10 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 7 Jun 2019 12:46:39 +0000 (13:46 +0100)
Not all platforms have it.  Use libiberty xstrndup() instead.

(The include of libiberty.h happens in an unusual place due to the
requirements of synchronization of most source files between this
project and another that does not use libiberty.  It serves to pull
libiberty.h in for all source files in libctf/, which does the trick.)

Tested on x86_64-pc-linux-gnu, x86_64-unknown-freebsd12.0,
sparc-sun-solaris2.11, i686-pc-cygwin, i686-w64-mingw32.

libctf/
* ctf-decls.h: Include <libiberty.h>.
* ctf-lookup.c (ctf_lookup_by_name): Call xstrndup(), not strndup().

libctf/ChangeLog
libctf/ctf-decls.h
libctf/ctf-lookup.c

index 20f9816efd4a7340c0f1a5fc7cae7b6fd279b6a2..f48ad5b213dc3083254b1383c6d35193e21be2ed 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-06  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-decls.h: Include <libiberty.h>.
+       * ctf-lookup.c (ctf_lookup_by_name): Call xstrndup(), not strndup().
+
 2019-06-06  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-dump.c (ctf_dump_format_type): Cast size_t's used in printf()s.
index c840b793c9bdf8cb9983c42dd9f860f3c04a2e90..b60a48f987ae0e47bb3e44d9892cb8c0ecb552e0 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stddef.h>
 #include <stdlib.h>
+#include "libiberty.h"
 
 #if HAVE_QSORT_R_ARG_LAST
 static inline void
index ab12715f4b1d557116ab4a5bc34178a453b3bf0d..4089ad9ffa4f86253722f83eb0d90b401f5c5f84 100644 (file)
@@ -153,7 +153,7 @@ ctf_lookup_by_name (ctf_file_t *fp, const char *name)
              else
                {
                  free (fp->ctf_tmp_typeslice);
-                 fp->ctf_tmp_typeslice = strndup (p, (size_t) (q - p));
+                 fp->ctf_tmp_typeslice = xstrndup (p, (size_t) (q - p));
                  if (fp->ctf_tmp_typeslice == NULL)
                    {
                      (void) ctf_set_errno (fp, ENOMEM);