[COMMITTED] Fix off-by-one error in make_hex_string.

Message ID m3fvcji4mp.fsf@seba.sebabeach.org
State Committed
Headers

Commit Message

Doug Evans Dec. 13, 2014, 10:09 p.m. UTC
  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.
  

Comments

Joel Brobecker Dec. 13, 2014, 10:23 p.m. UTC | #1
> python print (objfile.build_id)
> ../../to-push/gdb/common/common-utils.c:139: internal-error: xsnprintf: Assertion `ret < size' failed.

Grrr, thank you! I don't understand why I didn't get that error,
though, as I ran the testsuite. That's weird...
  
Doug Evans Dec. 13, 2014, 10:26 p.m. UTC | #2
On Sat, Dec 13, 2014 at 2:23 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>> python print (objfile.build_id)
>> ../../to-push/gdb/common/common-utils.c:139: internal-error: xsnprintf: Assertion `ret < size' failed.
>
> Grrr, thank you! I don't understand why I didn't get that error,
> though, as I ran the testsuite. That's weird...

I can imagine it's because the toolchain you used didn't add a build id.
Just a guess though.
  
Joel Brobecker Dec. 13, 2014, 11:33 p.m. UTC | #3
> I can imagine it's because the toolchain you used didn't add a build id.
> Just a guess though.

Yes, that's probably it. We need a unit test framework... ;-)
  

Patch

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;
 }