diff options
author | wm4 <wm4@nowhere> | 2014-01-02 23:54:59 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-01-02 23:54:59 +0100 |
commit | 2cad237f8bea862923bf9e7e2d7c55544f6248e0 (patch) | |
tree | 907febddd4fb439bfa8b1058140000a7516f8955 /ta/ta_talloc.h | |
parent | d4f37174a16afad6394e48e203abb41252e382d2 (diff) | |
download | mpv-2cad237f8bea862923bf9e7e2d7c55544f6248e0.tar.bz2 mpv-2cad237f8bea862923bf9e7e2d7c55544f6248e0.tar.xz |
ta: check overflow in array realloc macros
Diffstat (limited to 'ta/ta_talloc.h')
-rw-r--r-- | ta/ta_talloc.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/ta/ta_talloc.h b/ta/ta_talloc.h index ff131a610e..409949495a 100644 --- a/ta/ta_talloc.h +++ b/ta/ta_talloc.h @@ -77,14 +77,17 @@ char *ta_talloc_asprintf_append_buffer(char *s, const char *fmt, ...) TA_PRF(2, #define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0])) -#define MP_RESIZE_ARRAY(ctx, p, count) do { \ - (p) = talloc_realloc_size((ctx), p, (count) * sizeof((p)[0])); } while (0) +#define MP_RESIZE_ARRAY(ctx, p, count) \ + do { \ + (p) = ta_xrealloc_size(ctx, p, \ + ta_calc_array_size(sizeof((p)[0]), count)); \ + } while (0) #define MP_TARRAY_GROW(ctx, p, nextidx) \ do { \ size_t nextidx_ = (nextidx); \ if (nextidx_ >= MP_TALLOC_ELEMS(p)) \ - MP_RESIZE_ARRAY(ctx, p, (nextidx_ + 1) * 2);\ + MP_RESIZE_ARRAY(ctx, p, ta_calc_prealloc_elems(nextidx_)); \ } while (0) #define MP_GROW_ARRAY(p, nextidx) MP_TARRAY_GROW(NULL, p, nextidx) |