Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/malloc-wrapper.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: malloc-wrapper.c,v 1.7 2018/05/13 13:49:04 jsing Exp $ */ | - | ||||||||||||||||||||||||
2 | /* | - | ||||||||||||||||||||||||
3 | * Copyright (c) 2014 Bob Beck | - | ||||||||||||||||||||||||
4 | * | - | ||||||||||||||||||||||||
5 | * Permission to use, copy, modify, and distribute this software for any | - | ||||||||||||||||||||||||
6 | * purpose with or without fee is hereby granted, provided that the above | - | ||||||||||||||||||||||||
7 | * copyright notice and this permission notice appear in all copies. | - | ||||||||||||||||||||||||
8 | * | - | ||||||||||||||||||||||||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | - | ||||||||||||||||||||||||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | - | ||||||||||||||||||||||||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | - | ||||||||||||||||||||||||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | - | ||||||||||||||||||||||||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | - | ||||||||||||||||||||||||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | - | ||||||||||||||||||||||||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | - | ||||||||||||||||||||||||
16 | */ | - | ||||||||||||||||||||||||
17 | #include <stdio.h> | - | ||||||||||||||||||||||||
18 | #include <stdlib.h> | - | ||||||||||||||||||||||||
19 | #include <string.h> | - | ||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | int | - | ||||||||||||||||||||||||
22 | CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t), | - | ||||||||||||||||||||||||
23 | void (*f)(void *)) | - | ||||||||||||||||||||||||
24 | { | - | ||||||||||||||||||||||||
25 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
26 | } | - | ||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | int | - | ||||||||||||||||||||||||
29 | CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int), | - | ||||||||||||||||||||||||
30 | void *(*r)(void *, size_t, const char *, int), void (*f)(void *)) | - | ||||||||||||||||||||||||
31 | { | - | ||||||||||||||||||||||||
32 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
33 | } | - | ||||||||||||||||||||||||
34 | - | |||||||||||||||||||||||||
35 | int | - | ||||||||||||||||||||||||
36 | CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *)) | - | ||||||||||||||||||||||||
37 | { | - | ||||||||||||||||||||||||
38 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
39 | } | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | int | - | ||||||||||||||||||||||||
42 | CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int), | - | ||||||||||||||||||||||||
43 | void (*f)(void *)) | - | ||||||||||||||||||||||||
44 | { | - | ||||||||||||||||||||||||
45 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
46 | } | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | int | - | ||||||||||||||||||||||||
49 | CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int), | - | ||||||||||||||||||||||||
50 | void (*r)(void *, void *, int, const char *, int, int), | - | ||||||||||||||||||||||||
51 | void (*f)(void *, int), void (*so)(long), long (*go)(void)) | - | ||||||||||||||||||||||||
52 | { | - | ||||||||||||||||||||||||
53 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
54 | } | - | ||||||||||||||||||||||||
55 | - | |||||||||||||||||||||||||
56 | - | |||||||||||||||||||||||||
57 | void | - | ||||||||||||||||||||||||
58 | CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t), | - | ||||||||||||||||||||||||
59 | void (**f)(void *)) | - | ||||||||||||||||||||||||
60 | { | - | ||||||||||||||||||||||||
61 | if (m != NULL)
| 0 | ||||||||||||||||||||||||
62 | *m = malloc; never executed: *m = malloc; | 0 | ||||||||||||||||||||||||
63 | if (r != NULL)
| 0 | ||||||||||||||||||||||||
64 | *r = realloc; never executed: *r = realloc; | 0 | ||||||||||||||||||||||||
65 | if (f != NULL)
| 0 | ||||||||||||||||||||||||
66 | *f = free; never executed: *f = free; | 0 | ||||||||||||||||||||||||
67 | } never executed: end of block | 0 | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | void | - | ||||||||||||||||||||||||
70 | CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int), | - | ||||||||||||||||||||||||
71 | void *(**r)(void *, size_t, const char *, int), void (**f)(void *)) | - | ||||||||||||||||||||||||
72 | { | - | ||||||||||||||||||||||||
73 | if (m != NULL)
| 0 | ||||||||||||||||||||||||
74 | *m = NULL; never executed: *m = ((void *)0) ; | 0 | ||||||||||||||||||||||||
75 | if (r != NULL)
| 0 | ||||||||||||||||||||||||
76 | *r = NULL; never executed: *r = ((void *)0) ; | 0 | ||||||||||||||||||||||||
77 | if (f != NULL)
| 0 | ||||||||||||||||||||||||
78 | *f = free; never executed: *f = free; | 0 | ||||||||||||||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | void | - | ||||||||||||||||||||||||
82 | CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *)) | - | ||||||||||||||||||||||||
83 | { | - | ||||||||||||||||||||||||
84 | if (m != NULL)
| 0 | ||||||||||||||||||||||||
85 | *m = malloc; never executed: *m = malloc; | 0 | ||||||||||||||||||||||||
86 | if (f != NULL)
| 0 | ||||||||||||||||||||||||
87 | *f = free; never executed: *f = free; | 0 | ||||||||||||||||||||||||
88 | } never executed: end of block | 0 | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | void | - | ||||||||||||||||||||||||
91 | CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int), | - | ||||||||||||||||||||||||
92 | void (**f)(void *)) | - | ||||||||||||||||||||||||
93 | { | - | ||||||||||||||||||||||||
94 | if (m != NULL)
| 0 | ||||||||||||||||||||||||
95 | *m = NULL; never executed: *m = ((void *)0) ; | 0 | ||||||||||||||||||||||||
96 | if (f != NULL)
| 0 | ||||||||||||||||||||||||
97 | *f = free; never executed: *f = free; | 0 | ||||||||||||||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | void | - | ||||||||||||||||||||||||
101 | CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int), | - | ||||||||||||||||||||||||
102 | void (**r)(void *, void *, int, const char *, int, int), | - | ||||||||||||||||||||||||
103 | void (**f)(void *, int), void (**so)(long), long (**go)(void)) | - | ||||||||||||||||||||||||
104 | { | - | ||||||||||||||||||||||||
105 | if (m != NULL)
| 0 | ||||||||||||||||||||||||
106 | *m = NULL; never executed: *m = ((void *)0) ; | 0 | ||||||||||||||||||||||||
107 | if (r != NULL)
| 0 | ||||||||||||||||||||||||
108 | *r = NULL; never executed: *r = ((void *)0) ; | 0 | ||||||||||||||||||||||||
109 | if (f != NULL)
| 0 | ||||||||||||||||||||||||
110 | *f = NULL; never executed: *f = ((void *)0) ; | 0 | ||||||||||||||||||||||||
111 | if (so != NULL)
| 0 | ||||||||||||||||||||||||
112 | *so = NULL; never executed: *so = ((void *)0) ; | 0 | ||||||||||||||||||||||||
113 | if (go != NULL)
| 0 | ||||||||||||||||||||||||
114 | *go = NULL; never executed: *go = ((void *)0) ; | 0 | ||||||||||||||||||||||||
115 | } never executed: end of block | 0 | ||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | void * | - | ||||||||||||||||||||||||
119 | CRYPTO_malloc_locked(int num, const char *file, int line) | - | ||||||||||||||||||||||||
120 | { | - | ||||||||||||||||||||||||
121 | if (num <= 0)
| 0 | ||||||||||||||||||||||||
122 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
123 | return malloc(num); never executed: return malloc(num); | 0 | ||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | void | - | ||||||||||||||||||||||||
127 | CRYPTO_free_locked(void *ptr) | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | free(ptr); | - | ||||||||||||||||||||||||
130 | } never executed: end of block | 0 | ||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||
132 | void * | - | ||||||||||||||||||||||||
133 | CRYPTO_malloc(int num, const char *file, int line) | - | ||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||
135 | if (num <= 0)
| 0 | ||||||||||||||||||||||||
136 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
137 | return malloc(num); never executed: return malloc(num); | 0 | ||||||||||||||||||||||||
138 | } | - | ||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | char * | - | ||||||||||||||||||||||||
141 | CRYPTO_strdup(const char *str, const char *file, int line) | - | ||||||||||||||||||||||||
142 | { | - | ||||||||||||||||||||||||
143 | return strdup(str); never executed: return (__extension__ (__builtin_constant_p ( str ) && ((size_t)(const void *)(( str ) + 1) - (size_t)(const void *)( str ) == 1) ? (((const char *) ( str ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ( str ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void *)0)) __retval = (char *) memcpy (__retval, str , __len); __retval; })) : __strdup ( str ))) ; never executed: __retval = (char *) memcpy (__retval, str , __len);
| 0 | ||||||||||||||||||||||||
144 | } | - | ||||||||||||||||||||||||
145 | - | |||||||||||||||||||||||||
146 | void * | - | ||||||||||||||||||||||||
147 | CRYPTO_realloc(void *ptr, int num, const char *file, int line) | - | ||||||||||||||||||||||||
148 | { | - | ||||||||||||||||||||||||
149 | if (num <= 0)
| 0 | ||||||||||||||||||||||||
150 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
151 | return realloc(ptr, num); never executed: return realloc(ptr, num); | 0 | ||||||||||||||||||||||||
152 | } | - | ||||||||||||||||||||||||
153 | - | |||||||||||||||||||||||||
154 | void * | - | ||||||||||||||||||||||||
155 | CRYPTO_realloc_clean(void *ptr, int old_len, int num, const char *file, | - | ||||||||||||||||||||||||
156 | int line) | - | ||||||||||||||||||||||||
157 | { | - | ||||||||||||||||||||||||
158 | if (num <= 0)
| 0 | ||||||||||||||||||||||||
159 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
160 | /* Original does not support shrinking. */ | - | ||||||||||||||||||||||||
161 | if (num < old_len)
| 0 | ||||||||||||||||||||||||
162 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
163 | return recallocarray(ptr, old_len, num, 1); never executed: return recallocarray(ptr, old_len, num, 1); | 0 | ||||||||||||||||||||||||
164 | } | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | void | - | ||||||||||||||||||||||||
167 | CRYPTO_free(void *ptr) | - | ||||||||||||||||||||||||
168 | { | - | ||||||||||||||||||||||||
169 | free(ptr); | - | ||||||||||||||||||||||||
170 | } never executed: end of block | 0 | ||||||||||||||||||||||||
171 | - | |||||||||||||||||||||||||
172 | void * | - | ||||||||||||||||||||||||
173 | CRYPTO_remalloc(void *a, int num, const char *file, int line) | - | ||||||||||||||||||||||||
174 | { | - | ||||||||||||||||||||||||
175 | free(a); | - | ||||||||||||||||||||||||
176 | return malloc(num); never executed: return malloc(num); | 0 | ||||||||||||||||||||||||
177 | } | - | ||||||||||||||||||||||||
178 | - | |||||||||||||||||||||||||
179 | void | - | ||||||||||||||||||||||||
180 | CRYPTO_set_mem_debug_options(long bits) | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | return; never executed: return; | 0 | ||||||||||||||||||||||||
183 | } | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | long | - | ||||||||||||||||||||||||
186 | CRYPTO_get_mem_debug_options(void) | - | ||||||||||||||||||||||||
187 | { | - | ||||||||||||||||||||||||
188 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
189 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |