[RFC 4/9] don't let hexify call strlen

Tom Tromey
2014-01-20T19:23:45Z

hexify had the same issue as bin2hex; and the fix is the same.

2014-01-20 Tom Tromey <tromey@redhat.com>

* common/rsp-low.c (hexify): Never take strlen of argument.

2014-01-20 Tom Tromey <tromey@redhat.com>

* remote-utils.c (monitor_output): Pass explicit length to
hexify.
---
gdb/ChangeLog | 4 ++++
gdb/common/rsp-low.c | 4 ----
gdb/gdbserver/ChangeLog | 5 +++++
gdb/gdbserver/remote-utils.c | 5 +++--
4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gdb/common/rsp-low.c b/gdb/common/rsp-low.c
index 9c5119b..feb6d0c 100644
--- a/gdb/common/rsp-low.c
+++ b/gdb/common/rsp-low.c
@@ -177,10 +177,6 @@ hexify (char *hex, const char *bin, int count)
{
int i;

- /* May use a length, or a nul-terminated string as input. */
- if (count == 0)
- count = strlen (bin);
-
for (i = 0; i < count; i++)
{
*hex++ = tohex ((*bin >> 4) & 0xf);
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 710d398..b2a84c3 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -1558,10 +1558,11 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
void
monitor_output (const char *msg)
{
- char *buf = xmalloc (strlen (msg) * 2 + 2);
+ int len = strlen (msg);
+ char *buf = xmalloc (len * 2 + 2);

buf[0] = 'O';
- hexify (buf + 1, msg, 0);
+ hexify (buf + 1, msg, len);

putpkt (buf);
free (buf);
--
1.8.1.4