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

[Xen-devel] [PATCH v4 08/34] vmap: Make the while loop less fishy.



It looks like it could underflow at first glance. That is
if i is zero and you get in the while loop with the
i--. However the postfix expression is evaluated after the
conditional so the loop is fine and won't execute (with i==0).

However in spirit of defense programming lets clarify
the loop conditional.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>

---
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Keir Fraser <keir@xxxxxxx>
Cc: Tim Deegan <tim@xxxxxxx>
---
---
 xen/common/vmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/common/vmap.c b/xen/common/vmap.c
index c57239f..be01285 100644
--- a/xen/common/vmap.c
+++ b/xen/common/vmap.c
@@ -246,8 +246,8 @@ void *vmalloc(size_t size)
     return va;
 
  error:
-    while ( i-- )
-        free_domheap_page(mfn_to_page(mfn_x(mfn[i])));
+    while ( i )
+        free_domheap_page(mfn_to_page(mfn_x(mfn[--i])));
     xfree(mfn);
     return NULL;
 }
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.