Debian Codegraph @

external/flac/flac_memory.c

raw symbols SCIP
1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2001-2009 Josh Coalson
3 * Copyright (C) 2011-2025 Xiph.Org Foundation
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * - Neither the name of the Xiph.org Foundation nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 //ppgb #ifdef HAVE_CONFIG_H
34 #include "flac_config.h"cxx . . $ `<file>/external/flac/flac_config.h`/
35 //ppgb #endif
36
37 #ifdef HAVE_STDINT_Hcxx . . $ `./flac_config.h:39:9`!
38 #include <stdint.h>
39 #endif
40
41 #include "flac_private_memory.h"cxx . . $ `<file>/external/flac/flac_private_memory.h`/
42 #include "flac_FLAC_assert.h"cxx . . $ `<file>/external/flac/flac_FLAC_assert.h`/
43 #include "flac_share_compat.h"cxx . . $ `<file>/external/flac/flac_share_compat.h`/
44 #include "flac_share_alloc.h"cxx . . $ `<file>/external/flac/flac_share_alloc.h`/
45
46 void *FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(size_t bytes, void **aligned_address)
47 {
48 void *x;
49
50 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_address);
51
52 #ifdef FLAC__ALIGN_MALLOC_DATA
53 /* align on 32-byte (256-bit) boundary */
54 x = safe_malloc_add_2op_(bytes, /*+*/31L);
55 *aligned_address = (void*)(((uintptr_t)x + 31L) & -32L);
56 #else
57 x = safe_malloc_cxx . . $ safe_malloc_(bfcfa4d6b7f7ef64).(bytes);
58 *aligned_address = x;
59 #endif
60 return x;
61 }
62
63 FLAC__boolcxx . . $ FLAC__bool# FLAC__memory_alloc_aligned_int32_arraycxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).(size_t elements, FLAC__int32cxx . . $ FLAC__int32# **unaligned_pointer, FLAC__int32cxx . . $ FLAC__int32# **aligned_pointer)
64 {
65 FLAC__int32cxx . . $ FLAC__int32# *pu; /* unaligned pointer */
66 unioncxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).$anonymous_type_0# { /* union needed to comply with C99 pointer aliasing rules */
67 FLAC__int32cxx . . $ FLAC__int32# *pacxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).$anonymous_type_0#pa.; /* aligned pointer */
68 void *pvcxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).$anonymous_type_0#pv.; /* aligned pointer alias */
69 } u;
70
71 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(elements > 0);
72 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != unaligned_pointer);
73 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_pointer);
74 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(unaligned_pointer != aligned_pointer);
75
76 if(elements > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / sizeof(*pu)) /* overflow check */
77 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
78
79 pu = FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(sizeof(*pu) * elements, &u.pvcxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).$anonymous_type_0#pv.);
80 if(0 == pu) {
81 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
82 }
83 else {
84 if(*unaligned_pointer != 0)
85 freecxx . . $ free(5d22bdacc48458e8).(*unaligned_pointer);
86 *unaligned_pointer = pu;
87 *aligned_pointer = u.pacxx . . $ FLAC__memory_alloc_aligned_int32_array(e43d86069415c433).$anonymous_type_0#pa.;
88 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
89 }
90 }
91
92 FLAC__boolcxx . . $ FLAC__bool# FLAC__memory_alloc_aligned_uint32_arraycxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).(size_t elements, FLAC__uint32cxx . . $ FLAC__uint32# **unaligned_pointer, FLAC__uint32cxx . . $ FLAC__uint32# **aligned_pointer)
93 {
94 FLAC__uint32cxx . . $ FLAC__uint32# *pu; /* unaligned pointer */
95 unioncxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).$anonymous_type_1# { /* union needed to comply with C99 pointer aliasing rules */
96 FLAC__uint32cxx . . $ FLAC__uint32# *pacxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).$anonymous_type_1#pa.; /* aligned pointer */
97 void *pvcxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).$anonymous_type_1#pv.; /* aligned pointer alias */
98 } u;
99
100 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(elements > 0);
101 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != unaligned_pointer);
102 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_pointer);
103 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(unaligned_pointer != aligned_pointer);
104
105 if(elements > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / sizeof(*pu)) /* overflow check */
106 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
107
108 pu = FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(sizeof(*pu) * elements, &u.pvcxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).$anonymous_type_1#pv.);
109 if(0 == pu) {
110 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
111 }
112 else {
113 if(*unaligned_pointer != 0)
114 freecxx . . $ free(5d22bdacc48458e8).(*unaligned_pointer);
115 *unaligned_pointer = pu;
116 *aligned_pointer = u.pacxx . . $ FLAC__memory_alloc_aligned_uint32_array(2e7c9c9aa04fa1bf).$anonymous_type_1#pa.;
117 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
118 }
119 }
120
121 FLAC__boolcxx . . $ FLAC__bool# FLAC__memory_alloc_aligned_int64_arraycxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).(size_t elements, FLAC__int64cxx . . $ FLAC__int64# **unaligned_pointer, FLAC__int64cxx . . $ FLAC__int64# **aligned_pointer)
122 {
123 FLAC__int64cxx . . $ FLAC__int64# *pu; /* unaligned pointer */
124 unioncxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).$anonymous_type_2# { /* union needed to comply with C99 pointer aliasing rules */
125 FLAC__int64cxx . . $ FLAC__int64# *pacxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).$anonymous_type_2#pa.; /* aligned pointer */
126 void *pvcxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).$anonymous_type_2#pv.; /* aligned pointer alias */
127 } u;
128
129 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(elements > 0);
130 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != unaligned_pointer);
131 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_pointer);
132 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(unaligned_pointer != aligned_pointer);
133
134 if(elements > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / sizeof(*pu)) /* overflow check */
135 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
136
137 pu = FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(sizeof(*pu) * elements, &u.pvcxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).$anonymous_type_2#pv.);
138 if(0 == pu) {
139 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
140 }
141 else {
142 if(*unaligned_pointer != 0)
143 freecxx . . $ free(5d22bdacc48458e8).(*unaligned_pointer);
144 *unaligned_pointer = pu;
145 *aligned_pointer = u.pacxx . . $ FLAC__memory_alloc_aligned_int64_array(453842ebad9b395).$anonymous_type_2#pa.;
146 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
147 }
148 }
149
150 FLAC__boolcxx . . $ FLAC__bool# FLAC__memory_alloc_aligned_uint64_arraycxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).(size_t elements, FLAC__uint64cxx . . $ FLAC__uint64# **unaligned_pointer, FLAC__uint64cxx . . $ FLAC__uint64# **aligned_pointer)
151 {
152 FLAC__uint64cxx . . $ FLAC__uint64# *pu; /* unaligned pointer */
153 unioncxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).$anonymous_type_3# { /* union needed to comply with C99 pointer aliasing rules */
154 FLAC__uint64cxx . . $ FLAC__uint64# *pacxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).$anonymous_type_3#pa.; /* aligned pointer */
155 void *pvcxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).$anonymous_type_3#pv.; /* aligned pointer alias */
156 } u;
157
158 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(elements > 0);
159 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != unaligned_pointer);
160 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_pointer);
161 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(unaligned_pointer != aligned_pointer);
162
163 if(elements > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / sizeof(*pu)) /* overflow check */
164 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
165
166 pu = FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(sizeof(*pu) * elements, &u.pvcxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).$anonymous_type_3#pv.);
167 if(0 == pu) {
168 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
169 }
170 else {
171 if(*unaligned_pointer != 0)
172 freecxx . . $ free(5d22bdacc48458e8).(*unaligned_pointer);
173 *unaligned_pointer = pu;
174 *aligned_pointer = u.pacxx . . $ FLAC__memory_alloc_aligned_uint64_array(33bb31e7046b17e).$anonymous_type_3#pa.;
175 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
176 }
177 }
178
179 #ifndef FLAC__INTEGER_ONLY_LIBRARY
180
181 FLAC__boolcxx . . $ FLAC__bool# FLAC__memory_alloc_aligned_real_arraycxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).(size_t elements, FLAC__realcxx . . $ FLAC__real# **unaligned_pointer, FLAC__realcxx . . $ FLAC__real# **aligned_pointer)
182 {
183 FLAC__realcxx . . $ FLAC__real# *pu; /* unaligned pointer */
184 unioncxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).$anonymous_type_4# { /* union needed to comply with C99 pointer aliasing rules */
185 FLAC__realcxx . . $ FLAC__real# *pacxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).$anonymous_type_4#pa.; /* aligned pointer */
186 void *pvcxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).$anonymous_type_4#pv.; /* aligned pointer alias */
187 } u;
188
189 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(elements > 0);
190 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != unaligned_pointer);
191 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(0 != aligned_pointer);
192 FLAC__ASSERTcxx . . $ `external/flac/flac_FLAC_assert.h:43:9`!(unaligned_pointer != aligned_pointer);
193
194 if(elements > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / sizeof(*pu)) /* overflow check */
195 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
196
197 pu = FLAC__memory_alloc_alignedcxx . . $ FLAC__memory_alloc_aligned(3549b1b4dc5bb17d).(sizeof(*pu) * elements, &u.pvcxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).$anonymous_type_4#pv.);
198 if(0 == pu) {
199 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
200 }
201 else {
202 if(*unaligned_pointer != 0)
203 freecxx . . $ free(5d22bdacc48458e8).(*unaligned_pointer);
204 *unaligned_pointer = pu;
205 *aligned_pointer = u.pacxx . . $ FLAC__memory_alloc_aligned_real_array(2085a33203e28f4).$anonymous_type_4#pa.;
206 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
207 }
208 }
209
210 #endif
211
212 void *safe_malloc_mul_2op_pcxx . . $ safe_malloc_mul_2op_p(63a7bf2941bfcd7a).(size_t size1, size_t size2)
213 {
214 if(!size1 || !size2)
215 return malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
216 if(size1 > SIZE_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:216:11`! / size2)
217 return 0;
218 return malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size1*size2);
219 }