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
547{547{
548 fast_malloc(ptr, size, min_size, 1);548 fast_malloc(ptr, size, min_size, 1);
549}549}
550
551int 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
31#include <stdint.h>31#include <stdint.h>
32 32
33#include "attributes.h"33#include "attributes.h"
34#include "error.h"
35#include "avutil.h"34#include "avutil.h"
36#include "version.h"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 * @param[out] r Pointer to the result of the operation671 * @param[out] r Pointer to the result of the operation
673 * @return 0 on success, AVERROR(EINVAL) on overflow672 * @return 0 on success, AVERROR(EINVAL) on overflow
674 */673 */
675static inline int av_size_mult(size_t a, size_t b, size_t *r)674int 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}
692 675
693/**676/**
694 * Set the maximum size that may be allocated in one block.677 * 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