diff options
author | William Henderson <william.henderson@nutanix.com> | 2023-08-23 09:38:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 09:38:30 +0100 |
commit | 149aa845b11bd13fca41dcf65b51283f83ac5520 (patch) | |
tree | 04f557f00a3693337102f5be678b6102bfb3b24b | |
parent | cfb7d908dca025bdea6709801c5790863e902ef8 (diff) | |
download | libvfio-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>
-rw-r--r-- | lib/dma.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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(®ion->info.iova), |