This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[pushed] Avoid use of sprintf in gdb/utils.c:make_hex_string


The use of sprintf is discouraged in GDB. Use xsnprintf instead.

gdb/ChangeLog:

        * utils.c (make_hex_string): Replace use of sprintf by use of
        xsnprintf.

Tested on x86_64-linux and pushed.

---
 gdb/ChangeLog | 5 +++++
 gdb/utils.c   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ac916de..c12de3a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2014-12-13  Joel Brobecker  <brobecker@adacore.com>
 
+	* utils.c (make_hex_string): Replace use of sprintf by use of
+	xsnprintf.
+
+2014-12-13  Joel Brobecker  <brobecker@adacore.com>
+
 	* compile/compile-object-load.c (link_callbacks_multiple_definition)
 	(link_callbacks_warning, link_callbacks_einfo): Remove trailing
 	newline at end of warning message.
diff --git a/gdb/utils.c b/gdb/utils.c
index 1ab183c..ea2b18a 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1124,7 +1124,7 @@ make_hex_string (const gdb_byte *data, size_t length)
 
   p = result;
   for (i = 0; i < length; ++i)
-    p += sprintf (p, "%02x", data[i]);
+    p += xsnprintf (p, 2, "%02x", data[i]);
   *p = '\0';
   return result;
 }
-- 
1.9.1


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