From: Ian Jackson Date: Thu, 18 Feb 2016 12:37:04 +0000 (+0000) Subject: tools: libxl: Simplify logic in libxl__realloc X-Git-Tag: 4.7.0-rc1~542 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=435bbbc9af0f38d304e8be3a1ba00b99af530d60;p=people%2Fandrewcoop%2Fxen.git tools: libxl: Simplify logic in libxl__realloc 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 Acked-by: Ian Campbell --- diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index fc81130b8e..e7b765bb99 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;