xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools: libxl: Simplify logic in libxl__realloc
@ 2016-02-19 15:34 Ian Jackson
  2016-02-25 10:14 ` Ian Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Jackson @ 2016-02-19 15:34 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Ian Campbell

Replace the loop exit and separate test for loop overrun with an
assert in the loop body.

This simplifies the code.  It also (hopefully) avoids Coverity
thinking that gc->alloc_maxsize might change, resulting in the loop
failing to find the right answer but also failing to abort.

(gc->alloc_maxsize can't change because gcs are all singlethreaded:
either they are on the stack of a specific thread, or they belong to
an ao and are covered by the ctx lock.)

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libxl/libxl_internal.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index fc81130..e7b765b 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -116,16 +116,13 @@ void *libxl__realloc(libxl__gc *gc, void *ptr, size_t new_size)
     if (ptr == NULL) {
         libxl__ptr_add(gc, new_ptr);
     } else if (new_ptr != ptr && libxl__gc_is_real(gc)) {
-        for (i = 0; i < gc->alloc_maxsize; i++) {
+        for (i = 0; ; i++) {
+            assert(i < gc->alloc_maxsize);
             if (gc->alloc_ptrs[i] == ptr) {
                 gc->alloc_ptrs[i] = new_ptr;
                 break;
             }
         }
-        if (i == gc->alloc_maxsize) {
-            LOG(CRITICAL, "pointer is not tracked by the given gc");
-            abort();
-        }
     }
 
     return new_ptr;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-01 15:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-19 15:34 [PATCH] tools: libxl: Simplify logic in libxl__realloc Ian Jackson
2016-02-25 10:14 ` Ian Campbell
2016-03-01 15:44   ` Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).