[binutils-gdb] libctf: avoid strndup
Jose E.Marchesi
jemarch@sourceware.org
Fri Jun 7 13:11:00 GMT 2019
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=942d35f72bea5a0d19a5d0e0a5ca533e37a88b2c
commit 942d35f72bea5a0d19a5d0e0a5ca533e37a88b2c
Author: Nick Alcock <nick.alcock@oracle.com>
Date: Thu Jun 6 14:10:08 2019 +0100
libctf: avoid strndup
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().
Diff:
---
libctf/ChangeLog | 5 +++++
libctf/ctf-decls.h | 1 +
libctf/ctf-lookup.c | 2 +-
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 20f9816..f48ad5b 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,10 @@
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.
(ctf_dump_objts): Likewise.
(ctf_dump_funcs): Likewise.
diff --git a/libctf/ctf-decls.h b/libctf/ctf-decls.h
index c840b79..b60a48f 100644
--- a/libctf/ctf-decls.h
+++ b/libctf/ctf-decls.h
@@ -24,6 +24,7 @@
#include <stddef.h>
#include <stdlib.h>
+#include "libiberty.h"
#if HAVE_QSORT_R_ARG_LAST
static inline void
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index ab12715..4089ad9 100644
--- a/libctf/ctf-lookup.c
+++ b/libctf/ctf-lookup.c
@@ -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);
More information about the Binutils-cvs
mailing list