FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/mem.c
Date: 2026-08-15 14:54:27
Exec Total Coverage
Lines: 228 250 91.2%
Functions: 28 28 100.0%
Branches: 107 146 73.3%

Line Branch Exec Source
1 /*
2 * default memory allocator for libavutil
3 * Copyright (c) 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * default memory allocator for libavutil
25 */
26
27 #define _XOPEN_SOURCE 600
28
29 #include "config.h"
30
31 #include <limits.h>
32 #include <stdint.h>
33 #include <stdlib.h>
34 #include <stdatomic.h>
35 #include <string.h>
36 #if HAVE_MALLOC_H
37 #include <malloc.h>
38 #endif
39
40 #include "attributes.h"
41 #include "avassert.h"
42 #include "dynarray.h"
43 #include "error.h"
44 #include "internal.h"
45 #include "intreadwrite.h"
46 #include "macros.h"
47 #include "mem.h"
48
49 #ifdef MALLOC_PREFIX
50
51 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
52 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
53 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
54 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
55 #define free AV_JOIN(MALLOC_PREFIX, free)
56
57 void *malloc(size_t size);
58 void *memalign(size_t align, size_t size);
59 int posix_memalign(void **ptr, size_t align, size_t size);
60 void *realloc(void *ptr, size_t size);
61 void free(void *ptr);
62
63 #endif /* MALLOC_PREFIX */
64
65 #define ALIGN (HAVE_SIMD_ALIGN_64 ? 64 : (HAVE_SIMD_ALIGN_32 ? 32 : 16))
66
67 #define FF_MEMORY_POISON 0x2a
68
69 /* NOTE: if you want to override these functions with your own
70 * implementations (not recommended) you have to link libav* as
71 * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
72 * Note that this will cost performance. */
73
74 static atomic_size_t max_alloc_size = INT_MAX;
75
76 26 void av_max_alloc(size_t max){
77 26 atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed);
78 26 }
79
80 12218516 static int size_mult(size_t a, size_t b, size_t *r)
81 {
82 size_t t;
83
84 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow)
85
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12218516 times.
12218516 if (__builtin_mul_overflow(a, b, &t))
86 return AVERROR(EINVAL);
87 #else
88 t = a * b;
89 /* Hack inspired from glibc: don't try the division if nelem and elsize
90 * are both less than sqrt(SIZE_MAX). */
91 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
92 return AVERROR(EINVAL);
93 #endif
94 12218516 *r = t;
95 12218516 return 0;
96 }
97
98 63534204 void *av_malloc(size_t size)
99 {
100 63534204 void *ptr = NULL;
101
102
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 63534183 times.
63534204 if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
103 21 return NULL;
104
105 #if HAVE_POSIX_MEMALIGN
106
2/2
✓ Branch 0 taken 63514700 times.
✓ Branch 1 taken 19483 times.
63534183 if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 63514700 times.
63514700 if (posix_memalign(&ptr, ALIGN, size))
108 ptr = NULL;
109 #elif HAVE_ALIGNED_MALLOC
110 ptr = _aligned_malloc(size, ALIGN);
111 #elif HAVE_MEMALIGN
112 #ifndef __DJGPP__
113 ptr = memalign(ALIGN, size);
114 #else
115 ptr = memalign(size, ALIGN);
116 #endif
117 /* Why 64?
118 * Indeed, we should align it:
119 * on 4 for 386
120 * on 16 for 486
121 * on 32 for 586, PPro - K6-III
122 * on 64 for K7 (maybe for P3 too).
123 * Because L1 and L2 caches are aligned on those values.
124 * But I don't want to code such logic here!
125 */
126 /* Why 32?
127 * For AVX ASM. SSE / NEON needs only 16.
128 * Why not larger? Because I did not see a difference in benchmarks ...
129 */
130 /* benchmarks with P3
131 * memalign(64) + 1 3071, 3051, 3032
132 * memalign(64) + 2 3051, 3032, 3041
133 * memalign(64) + 4 2911, 2896, 2915
134 * memalign(64) + 8 2545, 2554, 2550
135 * memalign(64) + 16 2543, 2572, 2563
136 * memalign(64) + 32 2546, 2545, 2571
137 * memalign(64) + 64 2570, 2533, 2558
138 *
139 * BTW, malloc seems to do 8-byte alignment by default here.
140 */
141 #else
142 ptr = malloc(size);
143 #endif
144
3/4
✓ Branch 0 taken 19483 times.
✓ Branch 1 taken 63514700 times.
✓ Branch 2 taken 19483 times.
✗ Branch 3 not taken.
63534183 if(!ptr && !size) {
145 19483 size = 1;
146 19483 ptr= av_malloc(1);
147 }
148 #if CONFIG_MEMORY_POISONING
149
1/2
✓ Branch 0 taken 63534183 times.
✗ Branch 1 not taken.
63534183 if (ptr)
150 63534183 memset(ptr, FF_MEMORY_POISON, size);
151 #endif
152 63534183 return ptr;
153 }
154
155 25815074 void *av_realloc(void *ptr, size_t size)
156 {
157 void *ret;
158
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25815073 times.
25815074 if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
159 1 return NULL;
160
161 #if HAVE_ALIGNED_MALLOC
162 ret = _aligned_realloc(ptr, size + !size, ALIGN);
163 #else
164 25815073 ret = realloc(ptr, size + !size);
165 #endif
166 #if CONFIG_MEMORY_POISONING
167
3/4
✓ Branch 0 taken 25815073 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10526584 times.
✓ Branch 3 taken 15288489 times.
25815073 if (ret && !ptr)
168 10526584 memset(ret, FF_MEMORY_POISON, size);
169 #endif
170 25815073 return ret;
171 }
172
173 68562 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
174 {
175 size_t size;
176 void *r;
177
178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 68562 times.
68562 if (size_mult(elsize, nelem, &size)) {
179 av_free(ptr);
180 return NULL;
181 }
182 68562 r = av_realloc(ptr, size);
183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68562 times.
68562 if (!r)
184 av_free(ptr);
185 68562 return r;
186 }
187
188 21863 int av_reallocp(void *ptr, size_t size)
189 {
190 void *val;
191
192
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 21854 times.
21863 if (!size) {
193 9 av_freep(ptr);
194 9 return 0;
195 }
196
197 21854 memcpy(&val, ptr, sizeof(val));
198 21854 val = av_realloc(val, size);
199
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21854 times.
21854 if (!val) {
201 av_freep(ptr);
202 return AVERROR(ENOMEM);
203 }
204
205 21854 memcpy(ptr, &val, sizeof(val));
206 21854 return 0;
207 }
208
209 793672 void *av_malloc_array(size_t nmemb, size_t size)
210 {
211 size_t result;
212
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 793672 times.
793672 if (size_mult(nmemb, size, &result) < 0)
213 return NULL;
214 793672 return av_malloc(result);
215 }
216
217 7108880 void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
218 {
219 size_t result;
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7108880 times.
7108880 if (size_mult(nmemb, size, &result) < 0)
221 return NULL;
222 7108880 return av_realloc(ptr, result);
223 }
224
225 7214 int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
226 {
227 void *val;
228
229 7214 memcpy(&val, ptr, sizeof(val));
230 7214 val = av_realloc_f(val, nmemb, size);
231 7214 memcpy(ptr, &val, sizeof(val));
232
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 7214 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7214 if (!val && nmemb && size)
233 return AVERROR(ENOMEM);
234
235 7214 return 0;
236 }
237
238 130186208 void av_free(void *ptr)
239 {
240 #if HAVE_ALIGNED_MALLOC
241 _aligned_free(ptr);
242 #else
243 130186208 free(ptr);
244 #endif
245 130186208 }
246
247 83801564 void av_freep(void *arg)
248 {
249 void *val;
250
251 83801564 memcpy(&val, arg, sizeof(val));
252 83801564 memcpy(arg, &(void *){ NULL }, sizeof(val));
253 83801564 av_free(val);
254 83801564 }
255
256 39504631 void *av_mallocz(size_t size)
257 {
258 39504631 void *ptr = av_malloc(size);
259
2/2
✓ Branch 0 taken 39504617 times.
✓ Branch 1 taken 14 times.
39504631 if (ptr)
260 39504617 memset(ptr, 0, size);
261 39504631 return ptr;
262 }
263
264 4234556 void *av_calloc(size_t nmemb, size_t size)
265 {
266 size_t result;
267
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4234556 times.
4234556 if (size_mult(nmemb, size, &result) < 0)
268 return NULL;
269 4234556 return av_mallocz(result);
270 }
271
272 2554590 char *av_strdup(const char *s)
273 {
274 2554590 char *ptr = NULL;
275
2/2
✓ Branch 0 taken 2554589 times.
✓ Branch 1 taken 1 times.
2554590 if (s) {
276 2554589 size_t len = strlen(s) + 1;
277 2554589 ptr = av_realloc(NULL, len);
278
1/2
✓ Branch 0 taken 2554589 times.
✗ Branch 1 not taken.
2554589 if (ptr)
279 2554589 memcpy(ptr, s, len);
280 }
281 2554590 return ptr;
282 }
283
284 11 char *av_strndup(const char *s, size_t len)
285 {
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!s)
287 return NULL;
288
289 11 const char *end = memchr(s, 0, len);
290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (end)
291 len = end - s;
292
293 11 char *ret = av_realloc(NULL, len + 1);
294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (!ret)
295 return NULL;
296
297 11 memcpy(ret, s, len);
298 11 ret[len] = 0;
299 11 return ret;
300 }
301
302 11722973 void *av_memdup(const void *p, size_t size)
303 {
304 11722973 void *ptr = NULL;
305
1/2
✓ Branch 0 taken 11722973 times.
✗ Branch 1 not taken.
11722973 if (p) {
306 11722973 ptr = av_malloc(size);
307
1/2
✓ Branch 0 taken 11722973 times.
✗ Branch 1 not taken.
11722973 if (ptr)
308 11722973 memcpy(ptr, p, size);
309 }
310 11722973 return ptr;
311 }
312
313 236864 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
314 {
315 void **tab;
316 236864 memcpy(&tab, tab_ptr, sizeof(tab));
317
318
7/10
✓ Branch 0 taken 229969 times.
✓ Branch 1 taken 6895 times.
✓ Branch 2 taken 59903 times.
✓ Branch 3 taken 170066 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 229969 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 229969 times.
✓ Branch 9 taken 236864 times.
✗ Branch 10 not taken.
236864 FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
319 tab[*nb_ptr] = elem;
320 memcpy(tab_ptr, &tab, sizeof(tab));
321 }, {
322 return AVERROR(ENOMEM);
323 });
324 236864 return 0;
325 }
326
327 1371 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
328 {
329 void **tab;
330 1371 memcpy(&tab, tab_ptr, sizeof(tab));
331
332
7/10
✓ Branch 0 taken 266 times.
✓ Branch 1 taken 1105 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 106 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 266 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 266 times.
✓ Branch 9 taken 1371 times.
✗ Branch 10 not taken.
1371 FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
333 tab[*nb_ptr] = elem;
334 memcpy(tab_ptr, &tab, sizeof(tab));
335 }, {
336 *nb_ptr = 0;
337 av_freep(tab_ptr);
338 });
339 1371 }
340
341 24234545 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
342 const uint8_t *elem_data)
343 {
344 24234545 uint8_t *tab_elem_data = NULL;
345
346
9/12
✓ Branch 0 taken 12038925 times.
✓ Branch 1 taken 12195620 times.
✓ Branch 2 taken 8831215 times.
✓ Branch 3 taken 3207710 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 12038925 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12038925 times.
✓ Branch 9 taken 24234545 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 10794252 times.
✓ Branch 12 taken 13440293 times.
24234545 FF_DYNARRAY_ADD(INT_MAX, elem_size, *tab_ptr, *nb_ptr, {
347 tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
348 if (elem_data)
349 memcpy(tab_elem_data, elem_data, elem_size);
350 else if (CONFIG_MEMORY_POISONING)
351 memset(tab_elem_data, FF_MEMORY_POISON, elem_size);
352 }, {
353 av_freep(tab_ptr);
354 *nb_ptr = 0;
355 });
356 24234545 return tab_elem_data;
357 }
358
359 147132 static void fill16(uint8_t *dst, int len)
360 {
361 147132 uint32_t v = AV_RN16(dst - 2);
362
363 147132 v |= v << 16;
364
365
2/2
✓ Branch 0 taken 82898346 times.
✓ Branch 1 taken 147132 times.
83045478 while (len >= 4) {
366 82898346 AV_WN32(dst, v);
367 82898346 dst += 4;
368 82898346 len -= 4;
369 }
370
371
2/2
✓ Branch 0 taken 282093 times.
✓ Branch 1 taken 147132 times.
429225 while (len--) {
372 282093 *dst = dst[-2];
373 282093 dst++;
374 }
375 147132 }
376
377 738 static void fill24(uint8_t *dst, int len)
378 {
379 #if HAVE_BIGENDIAN
380 uint32_t v = AV_RB24(dst - 3);
381 uint32_t a = v << 8 | v >> 16;
382 uint32_t b = v << 16 | v >> 8;
383 uint32_t c = v << 24 | v;
384 #else
385 738 uint32_t v = AV_RL24(dst - 3);
386 738 uint32_t a = v | v << 24;
387 738 uint32_t b = v >> 8 | v << 16;
388 738 uint32_t c = v >> 16 | v << 8;
389 #endif
390
391
2/2
✓ Branch 0 taken 2508 times.
✓ Branch 1 taken 738 times.
3246 while (len >= 12) {
392 2508 AV_WN32(dst, a);
393 2508 AV_WN32(dst + 4, b);
394 2508 AV_WN32(dst + 8, c);
395 2508 dst += 12;
396 2508 len -= 12;
397 }
398
399
2/2
✓ Branch 0 taken 283 times.
✓ Branch 1 taken 455 times.
738 if (len >= 4) {
400 283 AV_WN32(dst, a);
401 283 dst += 4;
402 283 len -= 4;
403 }
404
405
2/2
✓ Branch 0 taken 157 times.
✓ Branch 1 taken 581 times.
738 if (len >= 4) {
406 157 AV_WN32(dst, b);
407 157 dst += 4;
408 157 len -= 4;
409 }
410
411
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 738 times.
2318 while (len--) {
412 1580 *dst = dst[-3];
413 1580 dst++;
414 }
415 738 }
416
417 15472 static void fill32(uint8_t *dst, int len)
418 {
419 15472 uint32_t v = AV_RN32(dst - 4);
420
421 #if HAVE_FAST_64BIT
422 15472 uint64_t v2= v + ((uint64_t)v<<32);
423
2/2
✓ Branch 0 taken 105234 times.
✓ Branch 1 taken 15472 times.
120706 while (len >= 32) {
424 105234 AV_WN64(dst , v2);
425 105234 AV_WN64(dst+ 8, v2);
426 105234 AV_WN64(dst+16, v2);
427 105234 AV_WN64(dst+24, v2);
428 105234 dst += 32;
429 105234 len -= 32;
430 }
431 #endif
432
433
2/2
✓ Branch 0 taken 60901 times.
✓ Branch 1 taken 15472 times.
76373 while (len >= 4) {
434 60901 AV_WN32(dst, v);
435 60901 dst += 4;
436 60901 len -= 4;
437 }
438
439
2/2
✓ Branch 0 taken 2266 times.
✓ Branch 1 taken 15472 times.
17738 while (len--) {
440 2266 *dst = dst[-4];
441 2266 dst++;
442 }
443 15472 }
444
445 808219 void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
446 {
447 808219 const uint8_t *src = &dst[-back];
448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 808219 times.
808219 if (!back)
449 return;
450
451
2/2
✓ Branch 0 taken 5265 times.
✓ Branch 1 taken 802954 times.
808219 if (back == 1) {
452 5265 memset(dst, *src, cnt);
453
2/2
✓ Branch 0 taken 147132 times.
✓ Branch 1 taken 655822 times.
802954 } else if (back == 2) {
454 147132 fill16(dst, cnt);
455
2/2
✓ Branch 0 taken 738 times.
✓ Branch 1 taken 655084 times.
655822 } else if (back == 3) {
456 738 fill24(dst, cnt);
457
2/2
✓ Branch 0 taken 15472 times.
✓ Branch 1 taken 639612 times.
655084 } else if (back == 4) {
458 15472 fill32(dst, cnt);
459 } else {
460
2/2
✓ Branch 0 taken 104834 times.
✓ Branch 1 taken 534778 times.
639612 if (cnt >= 16) {
461 104834 int blocklen = back;
462
2/2
✓ Branch 0 taken 37416 times.
✓ Branch 1 taken 104834 times.
142250 while (cnt > blocklen) {
463 37416 memcpy(dst, src, blocklen);
464 37416 dst += blocklen;
465 37416 cnt -= blocklen;
466 37416 blocklen <<= 1;
467 }
468 104834 memcpy(dst, src, cnt);
469 104834 return;
470 }
471
2/2
✓ Branch 0 taken 116277 times.
✓ Branch 1 taken 418501 times.
534778 if (cnt >= 8) {
472 116277 AV_COPY32U(dst, src);
473 116277 AV_COPY32U(dst + 4, src + 4);
474 116277 src += 8;
475 116277 dst += 8;
476 116277 cnt -= 8;
477 }
478
2/2
✓ Branch 0 taken 383459 times.
✓ Branch 1 taken 151319 times.
534778 if (cnt >= 4) {
479 383459 AV_COPY32U(dst, src);
480 383459 src += 4;
481 383459 dst += 4;
482 383459 cnt -= 4;
483 }
484
2/2
✓ Branch 0 taken 192819 times.
✓ Branch 1 taken 341959 times.
534778 if (cnt >= 2) {
485 192819 AV_COPY16U(dst, src);
486 192819 src += 2;
487 192819 dst += 2;
488 192819 cnt -= 2;
489 }
490
2/2
✓ Branch 0 taken 118885 times.
✓ Branch 1 taken 415893 times.
534778 if (cnt)
491 118885 *dst = *src;
492 }
493 }
494
495 2026493 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
496 {
497 size_t max_size;
498
499
2/2
✓ Branch 0 taken 1906955 times.
✓ Branch 1 taken 119538 times.
2026493 if (min_size <= *size)
500 1906955 return ptr;
501
502 119538 max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
503 /* *size is an unsigned, so the real maximum is <= UINT_MAX. */
504 119538 max_size = FFMIN(max_size, UINT_MAX);
505
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 119538 times.
119538 if (min_size > max_size) {
507 *size = 0;
508 return NULL;
509 }
510
511 119538 min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
512
513 119538 ptr = av_realloc(ptr, min_size);
514 /* we could set this to the unmodified min_size but this is safer
515 * if the user lost the ptr and uses NULL now
516 */
517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 119538 times.
119538 if (!ptr)
518 min_size = 0;
519
520 119538 *size = min_size;
521
522 119538 return ptr;
523 }
524
525 372263 static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
526 {
527 size_t max_size;
528 void *val;
529
530 372263 memcpy(&val, ptr, sizeof(val));
531
2/2
✓ Branch 0 taken 316919 times.
✓ Branch 1 taken 55344 times.
372263 if (min_size <= *size) {
532
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 316919 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
316919 av_assert0(val || !min_size);
533 316919 return;
534 }
535
536 55344 max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
537 /* *size is an unsigned, so the real maximum is <= UINT_MAX. */
538 55344 max_size = FFMIN(max_size, UINT_MAX);
539
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55344 times.
55344 if (min_size > max_size) {
541 av_freep(ptr);
542 *size = 0;
543 return;
544 }
545 55344 min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
546 55344 av_freep(ptr);
547
2/2
✓ Branch 0 taken 52998 times.
✓ Branch 1 taken 2346 times.
55344 val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
548 55344 memcpy(ptr, &val, sizeof(val));
549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55344 times.
55344 if (!val)
550 min_size = 0;
551 55344 *size = min_size;
552 55344 return;
553 }
554
555 97492 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
556 {
557 97492 fast_malloc(ptr, size, min_size, 0);
558 97492 }
559
560 274771 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
561 {
562 274771 fast_malloc(ptr, size, min_size, 1);
563 274771 }
564
565 12846 int av_size_mult(size_t a, size_t b, size_t *r)
566 {
567 12846 return size_mult(a, b, r);
568 }
569