Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-05-27 17:58:57 +0300
committerJames Almer <jamrial@gmail.com>2021-05-31 15:02:06 +0300
commitbaf5cc5b7a016efaa0d9bf3dfe62ad74ef4ffafe (patch)
treedcbbf957e3a51c002b41e16b65c2f7ad128817ff /libavutil/mem.h
parent51f1194edae2020ec99b816bd045a29db0e469f8 (diff)
avutil/mem: use GCC builtins to check for overflow in av_size_mult()
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/mem.h')
-rw-r--r--libavutil/mem.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/libavutil/mem.h b/libavutil/mem.h
index e21a1feaae..c876111afb 100644
--- a/libavutil/mem.h
+++ b/libavutil/mem.h
@@ -674,11 +674,18 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
*/
static inline int av_size_mult(size_t a, size_t b, size_t *r)
{
- size_t t = a * b;
+ size_t t;
+
+#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow)
+ if (__builtin_mul_overflow(a, b, &t))
+ return AVERROR(EINVAL);
+#else
+ t = a * b;
/* Hack inspired from glibc: don't try the division if nelem and elsize
* are both less than sqrt(SIZE_MAX). */
if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
return AVERROR(EINVAL);
+#endif
*r = t;
return 0;
}