There seems to be no compelling reason for it to be inline.
Unified · Split
| @@ -547,3 +547,21 @@ void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size) · 546 unmodified lines | ||
| 547 | 547 | { |
| 548 | 548 | fast_malloc(ptr, size, min_size, 1); |
| 549 | 549 | } |
| 550 | + | |
| 551 | +int av_size_mult(size_t a, size_t b, size_t *r) | |
| 552 | +{ | |
| 553 | + size_t t; | |
| 554 | + | |
| 555 | +#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow) | |
| 556 | + if (__builtin_mul_overflow(a, b, &t)) | |
| 557 | + return AVERROR(EINVAL); | |
| 558 | +#else | |
| 559 | + t = a * b; | |
| 560 | + /* Hack inspired from glibc: don't try the division if nelem and elsize | |
| 561 | + * are both less than sqrt(SIZE_MAX). */ | |
| 562 | + if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b) | |
| 563 | + return AVERROR(EINVAL); | |
| 564 | +#endif | |
| 565 | + *r = t; | |
| 566 | + return 0; | |
| 567 | +} | |
| @@ -31,7 +31,6 @@ · 30 unmodified lines | ||
| 31 | 31 | #include <stdint.h> |
| 32 | 32 | |
| 33 | 33 | #include "attributes.h" |
| 34 | −#include "error.h" | |
| 35 | 34 | #include "avutil.h" |
| 36 | 35 | #include "version.h" |
| 37 | 36 | |
| @@ -672,23 +671,7 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, · 634 unmodified lines | ||
| 672 | 671 | * @param[out] r Pointer to the result of the operation |
| 673 | 672 | * @return 0 on success, AVERROR(EINVAL) on overflow |
| 674 | 673 | */ |
| 675 | −static inline int av_size_mult(size_t a, size_t b, size_t *r) | |
| 676 | −{ | |
| 677 | − size_t t; | |
| 678 | − | |
| 679 | −#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow) | |
| 680 | − if (__builtin_mul_overflow(a, b, &t)) | |
| 681 | − return AVERROR(EINVAL); | |
| 682 | −#else | |
| 683 | − t = a * b; | |
| 684 | − /* Hack inspired from glibc: don't try the division if nelem and elsize | |
| 685 | − * are both less than sqrt(SIZE_MAX). */ | |
| 686 | − if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b) | |
| 687 | − return AVERROR(EINVAL); | |
| 688 | −#endif | |
| 689 | − *r = t; | |
| 690 | − return 0; | |
| 691 | −} | |
| 674 | +int av_size_mult(size_t a, size_t b, size_t *r); | |
| 692 | 675 | |
| 693 | 676 | /** |
| 694 | 677 | * Set the maximum size that may be allocated in one block. |