Start 1.33.0 development cycle
[oweals/busybox.git] / libbb / xrealloc_vector.c
index 342ae536eb19e5b5e80d49983e07a68bb09bd178..dda5f3f7da3a32b5d0f403728ba54ddb350681db 100644 (file)
@@ -4,9 +4,8 @@
  *
  * Copyright (C) 2008 Denys Vlasenko
  *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
 #include "libbb.h"
 
 /* Resize (grow) malloced vector.
@@ -20,8 +19,9 @@
  * idx step, plus one: if idx == 0x20, vector[] is resized to 0x31,
  * thus last usable element is vector[0x30].
  *
- * In other words: after xrealloc_vector(v, 4, idx) it's ok to use
- * at least v[idx] and v[idx+1], for all idx values.
+ * In other words: after xrealloc_vector(v, 4, idx), with any idx,
+ * it's ok to use at least v[idx] and v[idx+1].
+ * v[idx+2] etc generally are not ok.
  *
  * New elements are zeroed out, but only if realloc was done
  * (not on every call). You can depend on v[idx] and v[idx+1] being
@@ -39,8 +39,7 @@ void* FAST_FUNC xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift,
        if (!(idx & (mask - 1))) {
                sizeof_and_shift >>= 8; /* sizeof(vector[0]) */
                vector = xrealloc(vector, sizeof_and_shift * (idx + mask + 1));
-               vector += idx;
-               memset(vector, 0, sizeof_and_shift * (mask + 1));
+               memset((char*)vector + (sizeof_and_shift * idx), 0, sizeof_and_shift * (mask + 1));
        }
        return vector;
 }