summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Bradbury <asb@igalia.com>2025-12-02 23:05:55 +0000
committerMichael Tokarev <mjt@tls.msk.ru>2026-02-12 20:51:07 +0300
commitb1b6d7a42694ea958b1210aeeee565873d549e5d (patch)
tree24cafa8735166b3ba19a1dd5983902683d748e6e
parent1d6ad5e8ebdd82623aa87e2e4da993b837c1879a (diff)
downloadqemu-b1b6d7a42694ea958b1210aeeee565873d549e5d.tar.gz
qemu-b1b6d7a42694ea958b1210aeeee565873d549e5d.zip
contrib/plugins/hotblocks: Fix off by one error in iteration of sorted blocks
The logic to iterate over the hottest blocks will never reach the last item in the list, as it checks `it->next != NULL` before entering the loop. It's hard to trigger this off-by-one error with the default limit=20, but it is a bug and is problematic if that default is changed to something larger. Signed-off-by: Alex Bradbury <asb@igalia.com> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Link: https://lore.kernel.org/qemu-devel/f1ba2e57c6126472c0c8310774009f2455efc370.1753857212.git.asb@igalia.com Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> (cherry picked from commit 1c1e45fcd66269f8a6dbd97fd7b8267d8f6f58af) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
-rw-r--r--contrib/plugins/hotblocks.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index d3dd23ed9f..cf4d6b8c36 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -82,10 +82,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
sorted_counts = g_list_sort_with_data(counts, cmp_exec_count, NULL);
if (sorted_counts) {
- it = sorted_counts;
g_string_append_printf(report, "pc, tcount, icount, ecount\n");
- for (i = 0; i < limit && it->next; i++, it = it->next) {
+ for (i = 0, it = sorted_counts; i < limit && it; i++, it = it->next) {
ExecCount *rec = (ExecCount *) it->data;
g_string_append_printf(
report, "0x%016"PRIx64", %d, %ld, %"PRId64"\n",