aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Henderson <william.henderson@nutanix.com>2023-08-23 09:38:30 +0100
committerGitHub <noreply@github.com>2023-08-23 09:38:30 +0100
commit149aa845b11bd13fca41dcf65b51283f83ac5520 (patch)
tree04f557f00a3693337102f5be678b6102bfb3b24b /lib
parentcfb7d908dca025bdea6709801c5790863e902ef8 (diff)
downloadlibvfio-user-149aa845b11bd13fca41dcf65b51283f83ac5520.zip
libvfio-user-149aa845b11bd13fca41dcf65b51283f83ac5520.tar.gz
libvfio-user-149aa845b11bd13fca41dcf65b51283f83ac5520.tar.bz2
fix: incorrect number of dirty pages printed (#766)
The `log_dirty_bitmap` function in `dma.c` would output the wrong number of dirty pages due to the `char` of the bitmap being sign-extended when implicitly being converted to `unsigned int` for `__builtin_popcount`. By adding an intermediate cast to `uint8_t` we avoid this incorrect behaviour. See https://github.com/nutanix/libvfio-user/pull/746#discussion_r1297173318. Signed-off-by: William Henderson <william.henderson@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dma.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/dma.c b/lib/dma.c
index af1495f..9ca34d0 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -535,7 +535,7 @@ log_dirty_bitmap(vfu_ctx_t *vfu_ctx, dma_memory_region_t *region,
size_t i;
size_t count;
for (i = 0, count = 0; i < size; i++) {
- count += __builtin_popcount(bitmap[i]);
+ count += __builtin_popcount((uint8_t)bitmap[i]);
}
vfu_log(vfu_ctx, LOG_DEBUG, "dirty pages: get [%p, %p), %zu dirty pages",
region->info.iova.iov_base, iov_end(&region->info.iova),