This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[COMMITTED PATCH] Fix off-by-one error in make_hex_string.
- From: Doug Evans <xdje42 at gmail dot com>
- To: gdb-patches at sourceware dot org, brobecker at adacore dot com
- Date: Sat, 13 Dec 2014 14:09:18 -0800
- Subject: [COMMITTED PATCH] Fix off-by-one error in make_hex_string.
- Authentication-results: sourceware.org; auth=none
Hi.
I noticed a failure in py-objfile.exp:
python print (objfile.build_id)
../../to-push/gdb/common/common-utils.c:139: internal-error: xsnprintf: Assertion `ret < size' failed.
It's just an off-by-one error in make_hex_string.
The size argument to xsnprintf must include the trailing nul,
but the result does not include it.
2014-12-13 Doug Evans <xdje42@gmail.com>
* utils.c (make_hex_string): Fix off-by-one error.
diff --git a/gdb/utils.c b/gdb/utils.c
index ea2b18a..47adb67 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 += xsnprintf (p, 2, "%02x", data[i]);
+ p += xsnprintf (p, 3, "%02x", data[i]);
*p = '\0';
return result;
}