Skip to content

Commit a51ac96

Browse files
committed
target: fix unsigned computation in 'monitor profile'
The implementation of command 'monitor profile' has few issues: - the address_space is a signed int, so cannot wrap-around on space over INT_MAX; - max address is incremented without check for overflow; - assert() used on errors instead of returning error codes; - only handles 32 bits PC; - output file created and left empty on error. This patch fixes the first two issues, as a wider fix would be too invasive and should be postponed in a following series. Change-Id: Id8ead3f6db0fd5730682a0d1638f11836d06a632 Signed-off-by: Antonio Borneo <[email protected]> Fixes: https://sourceforge.net/p/openocd/tickets/370/ Reviewed-on: https://review.openocd.org/c/openocd/+/7394 Tested-by: jenkins
1 parent a6b0221 commit a51ac96

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/target/target.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,10 +4251,11 @@ static void write_gmon(uint32_t *samples, uint32_t sample_num, const char *filen
42514251

42524252
/* max should be (largest sample + 1)
42534253
* Refer to binutils/gprof/hist.c (find_histogram_for_pc) */
4254-
max++;
4254+
if (max < UINT32_MAX)
4255+
max++;
42554256
}
42564257

4257-
int address_space = max - min;
4258+
uint32_t address_space = max - min;
42584259
assert(address_space >= 2);
42594260

42604261
/* FIXME: What is the reasonable number of buckets?

0 commit comments

Comments
 (0)