[PATCH kvm-unit-tests 04/10] alloc_page: fix off-by-one

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It is okay to free up to the very last page of virtual address space,
in which case mem+size is zero.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
 lib/alloc_page.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/alloc_page.c b/lib/alloc_page.c
index b02dfce..de6fd6f 100644
--- a/lib/alloc_page.c
+++ b/lib/alloc_page.c
@@ -19,7 +19,8 @@ void free_pages(void *mem, unsigned long size)
 
 	assert_msg(size % PAGE_SIZE == 0, "size not page aligned: %#lx", size);
 
-	assert_msg(size == 0 || mem + size > mem,
+	assert_msg(size == 0 || (uintptr_t)mem == -size ||
+		   (uintptr_t)mem + size > (uintptr_t)mem,
 		   "mem + size overflow: %p + %#lx", mem, size);
 
 	if (size == 0) {
-- 
2.14.2





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux