fixup reallocation to "twice the size + 1", instead of "3 times the size".
authorvhanquez@kneesa.uk.xensource.com <vhanquez@kneesa.uk.xensource.com>
Tue, 24 Jan 2006 10:52:52 +0000 (10:52 +0000)
committervhanquez@kneesa.uk.xensource.com <vhanquez@kneesa.uk.xensource.com>
Tue, 24 Jan 2006 10:52:52 +0000 (10:52 +0000)
max *= 2 + 1 <==> max *= 3

Signed-off-by: Vincent Hanquez <vincent@xensource.com>
tools/xenstore/utils.c

index 1bf8606b40eb57840dbc607922e9f06e278cda6f..f8bf989c22e96413c7bec49a0f0574984a92db26 100644 (file)
@@ -99,8 +99,10 @@ void *grab_file(const char *filename, unsigned long *size)
        *size = 0;
        while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
                *size += ret;
-               if (*size == max)
-                       buffer = realloc(buffer, max *= 2 + 1);
+               if (*size == max) {
+                       max *= 2;
+                       buffer = realloc(buffer, max + 1);
+               }
        }
        if (ret < 0) {
                free(buffer);