History

lavu/mem: un-inline av_size_mult()

There seems to be no compelling reason for it to be inline.

Anton Khirnov committed 5 years ago

Commit 580e1681 parent 71c0ef82 files · +19 −18Browse files

Unified · Split

2 files
  1. libavutil/mem.c +18 −0
  2. libavutil/mem.h +1 −18
libavutil/mem.c+18−0
@@ -547,3 +547,21 @@ void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size) · 546 unmodified lines
547547 {
548548 fast_malloc(ptr, size, min_size, 1);
549549 }
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+}
libavutil/mem.h+1−18
@@ -31,7 +31,6 @@ · 30 unmodified lines
3131 #include <stdint.h>
3232
3333 #include "attributes.h"
34−#include "error.h"
3534 #include "avutil.h"
3635 #include "version.h"
3736
@@ -672,23 +671,7 @@ void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, · 634 unmodified lines
672671 * @param[out] r Pointer to the result of the operation
673672 * @return 0 on success, AVERROR(EINVAL) on overflow
674673 */
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);
692675
693676 /**
694677 * Set the maximum size that may be allocated in one block.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t