Fix byte count when doing unaligned memory read, fix issue #127
authorNicolas Schodet <nico@ni.fr.eu.org>
Tue, 12 Feb 2013 18:38:46 +0000 (19:38 +0100)
committerNicolas Schodet <nico@ni.fr.eu.org>
Tue, 12 Feb 2013 18:38:46 +0000 (19:38 +0100)
 - when start is adjusted, count should also be adjusted,
 - then, count is rounded to the next multiple of word size.

gdbserver/gdb-server.c

index 1b5fc84012d576eade99505a3610266657d5a197..f92fc05f06aa7c11f437c67ab252561fbccf85bc 100644 (file)
@@ -1056,9 +1056,9 @@ start_again:
                        unsigned     count = strtoul(s_count, NULL, 16);
 
                        unsigned adj_start = start % 4;
+                       unsigned count_rnd = (count + adj_start + 4 - 1) / 4 * 4;
 
-                       stlink_read_mem32(sl, start - adj_start, (count % 4 == 0) ?
-                                               count : count + 4 - (count % 4));
+                       stlink_read_mem32(sl, start - adj_start, count_rnd);
 
                        reply = calloc(count * 2 + 1, 1);
                        for(unsigned int i = 0; i < count; i++) {