This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 3/3] 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.

	* ctf-decls.h: Include <libiberty.h>.
	* ctf-lookup.c (ctf_lookup_by_name): Call xstrndup(), not strndup().
 libctf/ctf-decls.h  | 1 +
 libctf/ctf-lookup.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/libctf/ctf-decls.h b/libctf/ctf-decls.h
index c840b793c9..b60a48f987 100644
--- a/libctf/ctf-decls.h
+++ b/libctf/ctf-decls.h
@@ -24,6 +24,7 @@
 #include <stddef.h>
 #include <stdlib.h>
+#include "libiberty.h"
 static inline void
diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c
index ab12715f4b..4089ad9ffa 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)
 		  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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]