Skip to content

Commit 1e427fd

Browse files
committed
server: gdb_server: fix memory map generation on a 32-bit BE host
Due to lack of printf format check wrong specifier was used and it actually broke operation on a 32-bit BE host. So fix this and add the necessary function attributes so that the bugs like that can be uncovered automaticaly. Reported and pinpointed by Karl Palsson on IRC. Change-Id: I254ec28fcd9bb30594d607f74a6dba5456c2c7a1 Tested-by: Karl Palsson <[email protected]> Signed-off-by: Paul Fertser <[email protected]> Reviewed-on: http://openocd.zylin.com/5342 Tested-by: jenkins Reviewed-by: Karl Palsson <[email protected]> Reviewed-by: Antonio Borneo <[email protected]>
1 parent 678fb4f commit 1e427fd

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/helper/log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ int log_add_callback(log_callback_fn fn, void *priv);
9595
int log_remove_callback(log_callback_fn fn, void *priv);
9696

9797
char *alloc_vprintf(const char *fmt, va_list ap);
98-
char *alloc_printf(const char *fmt, ...);
98+
char *alloc_printf(const char *fmt, ...)
99+
__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2)));
99100

100101
extern int debug_level;
101102

src/server/gdb_server.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection,
17291729
/* print out a string and allocate more space as needed,
17301730
* mainly used for XML at this point
17311731
*/
1732-
static void xml_printf(int *retval, char **xml, int *pos, int *size,
1733-
const char *fmt, ...)
1732+
static __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6))) void xml_printf(int *retval,
1733+
char **xml, int *pos, int *size, const char *fmt, ...)
17341734
{
17351735
if (*retval != ERROR_OK)
17361736
return;
@@ -1871,7 +1871,7 @@ static int gdb_memory_map(struct connection *connection,
18711871
if (ram_start < p->base)
18721872
xml_printf(&retval, &xml, &pos, &size,
18731873
"<memory type=\"ram\" start=\"" TARGET_ADDR_FMT "\" "
1874-
"length=\"0x%x\"/>\n",
1874+
"length=\"" TARGET_ADDR_FMT "\"/>\n",
18751875
ram_start, p->base - ram_start);
18761876

18771877
/* Report adjacent groups of same-size sectors. So for
@@ -2469,7 +2469,7 @@ static int gdb_generate_thread_list(struct target *target, char **thread_list_ou
24692469
xml_printf(&retval, &thread_list, &pos, &size,
24702470
", ");
24712471
xml_printf(&retval, &thread_list, &pos, &size,
2472-
thread_detail->extra_info_str);
2472+
"%s", thread_detail->extra_info_str);
24732473
}
24742474

24752475
xml_printf(&retval, &thread_list, &pos, &size,
@@ -3555,7 +3555,7 @@ static int gdb_target_add_one(struct target *target)
35553555
if (parse_long(gdb_port_next, &portnumber) == ERROR_OK) {
35563556
free(gdb_port_next);
35573557
if (portnumber) {
3558-
gdb_port_next = alloc_printf("%d", portnumber+1);
3558+
gdb_port_next = alloc_printf("%ld", portnumber+1);
35593559
} else {
35603560
/* Don't increment if gdb_port is 0, since we're just
35613561
* trying to allocate an unused port. */

0 commit comments

Comments
 (0)