Blender
V3.3
intern
guardedalloc
intern
mallocn_inline.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-2-Clause
2
* Copyright 2002-2017 Jason Evans <jasone@canonware.com>. All rights reserved.
3
* 2007-2012 Mozilla Foundation. All rights reserved.
4
* 2009-2017 Facebook, Inc. All rights reserved. */
5
10
#ifndef __MALLOCN_INLINE_H__
11
#define __MALLOCN_INLINE_H__
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
16
17
MEM_INLINE
bool
MEM_size_safe_multiply
(
size_t
a
,
size_t
b
,
size_t
*
result
)
18
{
19
/* A size_t with its high-half bits all set to 1. */
20
const
size_t
high_bits =
SIZE_MAX
<< (
sizeof
(size_t) * 8 / 2);
21
*
result
=
a
*
b
;
22
23
if
(
UNLIKELY
(*
result
== 0)) {
24
return
(
a
== 0 ||
b
== 0);
25
}
26
27
/*
28
* We got a non-zero size, but we don't know if we overflowed to get
29
* there. To avoid having to do a divide, we'll be clever and note that
30
* if both A and B can be represented in N/2 bits, then their product
31
* can be represented in N bits (without the possibility of overflow).
32
*/
33
return
((high_bits & (
a
|
b
)) == 0 || (*
result
/
b
==
a
));
34
}
35
36
#ifdef __cplusplus
37
}
38
#endif
39
40
#endif
/* __MALLOCN_INLINE_H__ */
result
double result
Definition:
BLI_expr_pylike_eval_test.cc:348
UNLIKELY
#define UNLIKELY(x)
Definition:
BLI_utildefines.h:753
MEM_size_safe_multiply
MEM_INLINE bool MEM_size_safe_multiply(size_t a, size_t b, size_t *result)
Definition:
mallocn_inline.h:17
MEM_INLINE
#define MEM_INLINE
Definition:
mallocn_intern.h:69
Freestyle::a
static unsigned a[3]
Definition:
RandGen.cpp:78
usdtokens::b
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
SIZE_MAX
#define SIZE_MAX
Definition:
stdint.h:206
Generated on Tue Oct 22 2024 13:18:25 for Blender by
doxygen
1.9.1