aboutsummaryrefslogtreecommitdiff
path: root/src/rtos
diff options
context:
space:
mode:
authorMarc Schink <openocd-dev@marcschink.de>2016-05-22 20:35:34 +0200
committerPaul Fertser <fercerpav@gmail.com>2016-12-08 12:34:53 +0000
commit69ff7354d9c9accf09374772310098f1f00e8ccb (patch)
tree94a7803244c884ec26965101d45e10f6c53d8477 /src/rtos
parent1461237073e377d315799999b8e29f1605084449 (diff)
downloadriscv-openocd-69ff7354d9c9accf09374772310098f1f00e8ccb.zip
riscv-openocd-69ff7354d9c9accf09374772310098f1f00e8ccb.tar.gz
riscv-openocd-69ff7354d9c9accf09374772310098f1f00e8ccb.tar.bz2
helper: Code cleanup for hexify()
Simplify hexify() and do not longer use 0 as special case for the parameter 'count' to determine the string length of the binary input. Instead, use strlen() outside of the function if needed. Additionally, fix the return value and return the length of the converted string. The old function always returned 2 * count. Also, use more appropriate data types for the function parameters and add a small documentation. Change-Id: I133a8ab786b8f7c1296afcaf9c0a0b43881e5112 Signed-off-by: Marc Schink <openocd-dev@marcschink.de> Reviewed-on: http://openocd.zylin.com/3793 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/rtos')
-rw-r--r--src/rtos/linux.c3
-rw-r--r--src/rtos/rtos.c7
2 files changed, 7 insertions, 3 deletions
diff --git a/src/rtos/linux.c b/src/rtos/linux.c
index 31d6618..e5a4efc 100644
--- a/src/rtos/linux.c
+++ b/src/rtos/linux.c
@@ -1229,7 +1229,8 @@ int linux_thread_extra_info(struct target *target,
sprintf(tmp_str_ptr, "%s", name);
sprintf(tmp_str_ptr, "%s", temp->name);
char *hex_str = calloc(1, strlen(tmp_str) * 2 + 1);
- int pkt_len = hexify(hex_str, tmp_str, 0, strlen(tmp_str) * 2 + 1);
+ size_t pkt_len = hexify(hex_str, (const uint8_t *)tmp_str,
+ strlen(tmp_str), strlen(tmp_str) * 2 + 1);
gdb_put_packet(connection, hex_str, pkt_len);
free(hex_str);
free(tmp_str);
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 6938336..84ee498 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -266,7 +266,9 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s
}
reply_len = snprintf(reply, sizeof(reply), "qSymbol:");
- reply_len += hexify(reply + reply_len, next_sym->symbol_name, 0, sizeof(reply) - reply_len);
+ reply_len += hexify(reply + reply_len,
+ (const uint8_t *)next_sym->symbol_name, strlen(next_sym->symbol_name),
+ sizeof(reply) - reply_len);
done:
gdb_put_packet(connection, reply, reply_len);
@@ -321,7 +323,8 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa
(size_t) (tmp_str_ptr - tmp_str));
char *hex_str = malloc(strlen(tmp_str) * 2 + 1);
- int pkt_len = hexify(hex_str, tmp_str, 0, strlen(tmp_str) * 2 + 1);
+ size_t pkt_len = hexify(hex_str, (const uint8_t *)tmp_str,
+ strlen(tmp_str), strlen(tmp_str) * 2 + 1);
gdb_put_packet(connection, hex_str, pkt_len);
free(hex_str);