Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
fx_memory_malloc.cpp
Go to the documentation of this file.
1
// Copyright 2022 The PDFium Authors
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7
#
include
"core/fxcrt/fx_memory.h"
8
9
#
include
<
stdlib
.
h
>
10
11
#
include
<
limits
>
12
13
#
include
"build/build_config.h"
14
#
include
"core/fxcrt/fx_safe_types.h"
15
16
#
if
defined
(
PDF_USE_PARTITION_ALLOC
)
17
#
error
"File compiled under wrong build option."
18
#
endif
19
20
namespace
pdfium
{
21
namespace
internal
{
22
23
// Slightly less than 2GB, typically.
24
constexpr
size_t
kMallocSizeLimit
=
std
::numeric_limits<
int
>::max() - (1 << 12);
25
26
void
*
Alloc
(size_t num_members, size_t member_size) {
27
FX_SAFE_SIZE_T total = member_size;
28
total *= num_members;
29
if
(!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
30
return
nullptr
;
31
return
malloc(total.ValueOrDie());
32
}
33
34
void
*
Calloc
(size_t num_members, size_t member_size) {
35
FX_SAFE_SIZE_T total = member_size;
36
total *= num_members;
37
if
(!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
38
return
nullptr
;
39
return
calloc(num_members, member_size);
40
}
41
42
void
*
Realloc
(
void
* ptr, size_t num_members, size_t member_size) {
43
FX_SAFE_SIZE_T total = num_members;
44
total *= member_size;
45
if
(!total.IsValid() || total.ValueOrDie() >= kMallocSizeLimit)
46
return
nullptr
;
47
return
realloc(ptr, total.ValueOrDie());
48
}
49
50
void
Dealloc
(
void
* ptr) {
51
free(ptr);
52
}
53
54
void
*
StringAlloc
(size_t num_members, size_t member_size) {
55
FX_SAFE_SIZE_T total = member_size;
56
total *= num_members;
57
if
(!total.IsValid())
58
return
nullptr
;
59
return
malloc(total.ValueOrDie());
60
}
61
62
void
StringDealloc
(
void
* ptr) {
63
free(ptr);
64
}
65
66
}
// namespace internal
67
}
// namespace pdfium
68
69
void
FX_InitializeMemoryAllocators
() {}
70
71
void
FX_DestroyMemoryAllocators
() {}
72
73
void
*
FX_ArrayBufferAllocate
(size_t length) {
74
void
* result = calloc(length, 1);
75
if
(!result)
76
FX_OutOfMemoryTerminate(length);
77
return
result;
78
}
79
80
void
*
FX_ArrayBufferAllocateUninitialized
(size_t length) {
81
void
* result = malloc(length);
82
if
(!result)
83
FX_OutOfMemoryTerminate(length);
84
return
result;
85
}
86
87
void
FX_ArrayBufferFree
(
void
* data) {
88
free(data);
89
}
pdfium::CFDETextOutLargeBitmapTest
Definition
cfde_textout_unittest.cpp:117
FX_ArrayBufferAllocate
void * FX_ArrayBufferAllocate(size_t length)
Definition
fx_memory_malloc.cpp:73
FX_DestroyMemoryAllocators
void FX_DestroyMemoryAllocators()
Definition
fx_memory_malloc.cpp:71
FX_InitializeMemoryAllocators
void FX_InitializeMemoryAllocators()
Definition
fx_memory_malloc.cpp:69
FX_ArrayBufferFree
void FX_ArrayBufferFree(void *data)
Definition
fx_memory_malloc.cpp:87
FX_ArrayBufferAllocateUninitialized
void * FX_ArrayBufferAllocateUninitialized(size_t length)
Definition
fx_memory_malloc.cpp:80
pdfium::internal
Definition
span.h:34
pdfium::internal::Alloc
void * Alloc(size_t num_members, size_t member_size)
Definition
fx_memory_malloc.cpp:26
pdfium::internal::StringAlloc
void * StringAlloc(size_t num_members, size_t member_size)
Definition
fx_memory_malloc.cpp:54
pdfium::internal::Realloc
void * Realloc(void *ptr, size_t num_members, size_t member_size)
Definition
fx_memory_malloc.cpp:42
pdfium::internal::StringDealloc
void StringDealloc(void *ptr)
Definition
fx_memory_malloc.cpp:62
pdfium::internal::kMallocSizeLimit
constexpr size_t kMallocSizeLimit
Definition
fx_memory_malloc.cpp:24
pdfium::internal::Calloc
void * Calloc(size_t num_members, size_t member_size)
Definition
fx_memory_malloc.cpp:34
pdfium::internal::Dealloc
void Dealloc(void *ptr)
Definition
fx_memory_malloc.cpp:50
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
fx_memory_malloc.cpp
Generated on
for Qt by
1.18.0