diff options
Diffstat (limited to 'src/util/common_allocation.c')
-rw-r--r-- | src/util/common_allocation.c | 294 |
1 files changed, 147 insertions, 147 deletions
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 94890a7f4..fd5af7a91 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file util/common_allocation.c | 22 | * @file util/common_allocation.c |
@@ -33,10 +33,10 @@ | |||
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define LOG(kind, ...) \ | 35 | #define LOG(kind, ...) \ |
36 | GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__) | 36 | GNUNET_log_from(kind, "util-common-allocation", __VA_ARGS__) |
37 | 37 | ||
38 | #define LOG_STRERROR(kind, syscall) \ | 38 | #define LOG_STRERROR(kind, syscall) \ |
39 | GNUNET_log_from_strerror (kind, "util-common-allocation", syscall) | 39 | GNUNET_log_from_strerror(kind, "util-common-allocation", syscall) |
40 | 40 | ||
41 | #ifndef INT_MAX | 41 | #ifndef INT_MAX |
42 | #define INT_MAX 0x7FFFFFFF | 42 | #define INT_MAX 0x7FFFFFFF |
@@ -63,19 +63,19 @@ static LONG mem_used = 0; | |||
63 | * @return pointer to size bytes of memory | 63 | * @return pointer to size bytes of memory |
64 | */ | 64 | */ |
65 | void * | 65 | void * |
66 | GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | 66 | GNUNET_xmalloc_(size_t size, const char *filename, int linenumber) |
67 | { | 67 | { |
68 | void *ret; | 68 | void *ret; |
69 | 69 | ||
70 | /* As a security precaution, we generally do not allow very large | 70 | /* As a security precaution, we generally do not allow very large |
71 | * allocations using the default 'GNUNET_malloc()' macro */ | 71 | * allocations using the default 'GNUNET_malloc()' macro */ |
72 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 72 | GNUNET_assert_at(size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
73 | ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); | 73 | ret = GNUNET_xmalloc_unchecked_(size, filename, linenumber); |
74 | if (NULL == ret) | 74 | if (NULL == ret) |
75 | { | 75 | { |
76 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 76 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "malloc"); |
77 | GNUNET_assert (0); | 77 | GNUNET_assert(0); |
78 | } | 78 | } |
79 | return ret; | 79 | return ret; |
80 | } | 80 | } |
81 | 81 | ||
@@ -95,23 +95,23 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) | |||
95 | * @return allocated memory, never NULL | 95 | * @return allocated memory, never NULL |
96 | */ | 96 | */ |
97 | void ** | 97 | void ** |
98 | GNUNET_xnew_array_2d_ (size_t n, | 98 | GNUNET_xnew_array_2d_(size_t n, |
99 | size_t m, | 99 | size_t m, |
100 | size_t elementSize, | 100 | size_t elementSize, |
101 | const char *filename, | 101 | const char *filename, |
102 | int linenumber) | 102 | int linenumber) |
103 | { | 103 | { |
104 | /* use char pointer internally to avoid void pointer arithmetic warnings */ | 104 | /* use char pointer internally to avoid void pointer arithmetic warnings */ |
105 | char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ | 105 | char **ret = GNUNET_xmalloc_(n * sizeof(void *) + /* 1. dim header */ |
106 | n * m * elementSize, /* element data */ | 106 | n * m * elementSize, /* element data */ |
107 | filename, | 107 | filename, |
108 | linenumber); | 108 | linenumber); |
109 | 109 | ||
110 | for (size_t i = 0; i < n; i++) | 110 | for (size_t i = 0; i < n; i++) |
111 | ret[i] = (char *) ret + /* base address */ | 111 | ret[i] = (char *)ret + /* base address */ |
112 | n * sizeof (void *) + /* skip 1. dim header */ | 112 | n * sizeof(void *) + /* skip 1. dim header */ |
113 | i * m * elementSize; /* skip to 2. dim row header */ | 113 | i * m * elementSize; /* skip to 2. dim row header */ |
114 | return (void **) ret; | 114 | return (void **)ret; |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
@@ -131,34 +131,34 @@ GNUNET_xnew_array_2d_ (size_t n, | |||
131 | * @return allocated memory, never NULL | 131 | * @return allocated memory, never NULL |
132 | */ | 132 | */ |
133 | void *** | 133 | void *** |
134 | GNUNET_xnew_array_3d_ (size_t n, | 134 | GNUNET_xnew_array_3d_(size_t n, |
135 | size_t m, | 135 | size_t m, |
136 | size_t o, | 136 | size_t o, |
137 | size_t elementSize, | 137 | size_t elementSize, |
138 | const char *filename, | 138 | const char *filename, |
139 | int linenumber) | 139 | int linenumber) |
140 | { | 140 | { |
141 | /* use char pointer internally to avoid void pointer arithmetic warnings */ | 141 | /* use char pointer internally to avoid void pointer arithmetic warnings */ |
142 | char ***ret = GNUNET_xmalloc_ (n * sizeof (void **) + /* 1. dim header */ | 142 | char ***ret = GNUNET_xmalloc_(n * sizeof(void **) + /* 1. dim header */ |
143 | n * m * sizeof (void *) + /* 2. dim header */ | 143 | n * m * sizeof(void *) + /* 2. dim header */ |
144 | n * m * o * elementSize, /* element data */ | 144 | n * m * o * elementSize, /* element data */ |
145 | filename, | 145 | filename, |
146 | linenumber); | 146 | linenumber); |
147 | 147 | ||
148 | for (size_t i = 0; i < n; i++) | 148 | for (size_t i = 0; i < n; i++) |
149 | { | 149 | { |
150 | /* need to cast to (char *) temporarily for byte level acuracy */ | 150 | /* need to cast to (char *) temporarily for byte level acuracy */ |
151 | ret[i] = (char **) ((char *) ret + /* base address */ | 151 | ret[i] = (char **)((char *)ret + /* base address */ |
152 | n * sizeof (void **) + /* skip 1. dim header */ | 152 | n * sizeof(void **) + /* skip 1. dim header */ |
153 | i * m * sizeof (void *)); /* skip to 2. dim header */ | 153 | i * m * sizeof(void *)); /* skip to 2. dim header */ |
154 | for (size_t j = 0; j < m; j++) | 154 | for (size_t j = 0; j < m; j++) |
155 | ret[i][j] = (char *) ret + /* base address */ | 155 | ret[i][j] = (char *)ret + /* base address */ |
156 | n * sizeof (void **) + /* skip 1. dim header */ | 156 | n * sizeof(void **) + /* skip 1. dim header */ |
157 | n * m * sizeof (void *) + /* skip 2. dim header */ | 157 | n * m * sizeof(void *) + /* skip 2. dim header */ |
158 | i * m * o * elementSize + /* skip to 2. dim part */ | 158 | i * m * o * elementSize + /* skip to 2. dim part */ |
159 | j * o * elementSize; /* skip to 3. dim row data */ | 159 | j * o * elementSize; /* skip to 3. dim row data */ |
160 | } | 160 | } |
161 | return (void ***) ret; | 161 | return (void ***)ret; |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
@@ -174,34 +174,34 @@ GNUNET_xnew_array_3d_ (size_t n, | |||
174 | * @return allocated memory, never NULL | 174 | * @return allocated memory, never NULL |
175 | */ | 175 | */ |
176 | void * | 176 | void * |
177 | GNUNET_xmemdup_ (const void *buf, | 177 | GNUNET_xmemdup_(const void *buf, |
178 | size_t size, | 178 | size_t size, |
179 | const char *filename, | 179 | const char *filename, |
180 | int linenumber) | 180 | int linenumber) |
181 | { | 181 | { |
182 | void *ret; | 182 | void *ret; |
183 | 183 | ||
184 | /* As a security precaution, we generally do not allow very large | 184 | /* As a security precaution, we generally do not allow very large |
185 | * allocations here */ | 185 | * allocations here */ |
186 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 186 | GNUNET_assert_at(size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
187 | #ifdef W32_MEM_LIMIT | 187 | #ifdef W32_MEM_LIMIT |
188 | size += sizeof (size_t); | 188 | size += sizeof(size_t); |
189 | if (mem_used + size > W32_MEM_LIMIT) | 189 | if (mem_used + size > W32_MEM_LIMIT) |
190 | return NULL; | 190 | return NULL; |
191 | #endif | 191 | #endif |
192 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); | 192 | GNUNET_assert_at(size < INT_MAX, filename, linenumber); |
193 | ret = malloc (size); | 193 | ret = malloc(size); |
194 | if (ret == NULL) | 194 | if (ret == NULL) |
195 | { | 195 | { |
196 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 196 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "malloc"); |
197 | GNUNET_assert (0); | 197 | GNUNET_assert(0); |
198 | } | 198 | } |
199 | #ifdef W32_MEM_LIMIT | 199 | #ifdef W32_MEM_LIMIT |
200 | *((size_t *) ret) = size; | 200 | *((size_t *)ret) = size; |
201 | ret = &((size_t *) ret)[1]; | 201 | ret = &((size_t *)ret)[1]; |
202 | mem_used += size; | 202 | mem_used += size; |
203 | #endif | 203 | #endif |
204 | GNUNET_memcpy (ret, buf, size); | 204 | GNUNET_memcpy(ret, buf, size); |
205 | return ret; | 205 | return ret; |
206 | } | 206 | } |
207 | 207 | ||
@@ -216,26 +216,26 @@ GNUNET_xmemdup_ (const void *buf, | |||
216 | * @return pointer to size bytes of memory, NULL if we do not have enough memory | 216 | * @return pointer to size bytes of memory, NULL if we do not have enough memory |
217 | */ | 217 | */ |
218 | void * | 218 | void * |
219 | GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) | 219 | GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber) |
220 | { | 220 | { |
221 | void *result; | 221 | void *result; |
222 | 222 | ||
223 | (void) filename; | 223 | (void)filename; |
224 | (void) linenumber; | 224 | (void)linenumber; |
225 | #ifdef W32_MEM_LIMIT | 225 | #ifdef W32_MEM_LIMIT |
226 | size += sizeof (size_t); | 226 | size += sizeof(size_t); |
227 | if (mem_used + size > W32_MEM_LIMIT) | 227 | if (mem_used + size > W32_MEM_LIMIT) |
228 | return NULL; | 228 | return NULL; |
229 | #endif | 229 | #endif |
230 | 230 | ||
231 | result = malloc (size); | 231 | result = malloc(size); |
232 | if (NULL == result) | 232 | if (NULL == result) |
233 | return NULL; | 233 | return NULL; |
234 | memset (result, 0, size); | 234 | memset(result, 0, size); |
235 | 235 | ||
236 | #ifdef W32_MEM_LIMIT | 236 | #ifdef W32_MEM_LIMIT |
237 | *((size_t *) result) = size; | 237 | *((size_t *)result) = size; |
238 | result = &((size_t *) result)[1]; | 238 | result = &((size_t *)result)[1]; |
239 | mem_used += size; | 239 | mem_used += size; |
240 | #endif | 240 | #endif |
241 | 241 | ||
@@ -255,24 +255,24 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) | |||
255 | * @return pointer to size bytes of memory | 255 | * @return pointer to size bytes of memory |
256 | */ | 256 | */ |
257 | void * | 257 | void * |
258 | GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | 258 | GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber) |
259 | { | 259 | { |
260 | (void) filename; | 260 | (void)filename; |
261 | (void) linenumber; | 261 | (void)linenumber; |
262 | 262 | ||
263 | #ifdef W32_MEM_LIMIT | 263 | #ifdef W32_MEM_LIMIT |
264 | n += sizeof (size_t); | 264 | n += sizeof(size_t); |
265 | ptr = &((size_t *) ptr)[-1]; | 265 | ptr = &((size_t *)ptr)[-1]; |
266 | mem_used = mem_used - *((size_t *) ptr) + n; | 266 | mem_used = mem_used - *((size_t *)ptr) + n; |
267 | #endif | 267 | #endif |
268 | ptr = realloc (ptr, n); | 268 | ptr = realloc(ptr, n); |
269 | if ((NULL == ptr) && (n > 0)) | 269 | if ((NULL == ptr) && (n > 0)) |
270 | { | 270 | { |
271 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); | 271 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "realloc"); |
272 | GNUNET_assert (0); | 272 | GNUNET_assert(0); |
273 | } | 273 | } |
274 | #ifdef W32_MEM_LIMIT | 274 | #ifdef W32_MEM_LIMIT |
275 | ptr = &((size_t *) ptr)[1]; | 275 | ptr = &((size_t *)ptr)[1]; |
276 | #endif | 276 | #endif |
277 | return ptr; | 277 | return ptr; |
278 | } | 278 | } |
@@ -286,15 +286,15 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | |||
286 | #endif | 286 | #endif |
287 | 287 | ||
288 | #if WINDOWS | 288 | #if WINDOWS |
289 | #define M_SIZE(p) _msize (p) | 289 | #define M_SIZE(p) _msize(p) |
290 | #endif | 290 | #endif |
291 | #if HAVE_MALLOC_NP_H | 291 | #if HAVE_MALLOC_NP_H |
292 | #include <malloc_np.h> | 292 | #include <malloc_np.h> |
293 | #endif | 293 | #endif |
294 | #if HAVE_MALLOC_USABLE_SIZE | 294 | #if HAVE_MALLOC_USABLE_SIZE |
295 | #define M_SIZE(p) malloc_usable_size (p) | 295 | #define M_SIZE(p) malloc_usable_size(p) |
296 | #elif HAVE_MALLOC_SIZE | 296 | #elif HAVE_MALLOC_SIZE |
297 | #define M_SIZE(p) malloc_size (p) | 297 | #define M_SIZE(p) malloc_size(p) |
298 | #endif | 298 | #endif |
299 | 299 | ||
300 | /** | 300 | /** |
@@ -306,28 +306,28 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | |||
306 | * @param linenumber where in the code was the call to GNUNET_free | 306 | * @param linenumber where in the code was the call to GNUNET_free |
307 | */ | 307 | */ |
308 | void | 308 | void |
309 | GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) | 309 | GNUNET_xfree_(void *ptr, const char *filename, int linenumber) |
310 | { | 310 | { |
311 | GNUNET_assert_at (NULL != ptr, filename, linenumber); | 311 | GNUNET_assert_at(NULL != ptr, filename, linenumber); |
312 | #ifdef W32_MEM_LIMIT | 312 | #ifdef W32_MEM_LIMIT |
313 | ptr = &((size_t *) ptr)[-1]; | 313 | ptr = &((size_t *)ptr)[-1]; |
314 | mem_used -= *((size_t *) ptr); | 314 | mem_used -= *((size_t *)ptr); |
315 | #endif | 315 | #endif |
316 | #if defined(M_SIZE) | 316 | #if defined(M_SIZE) |
317 | #if ENABLE_POISONING | 317 | #if ENABLE_POISONING |
318 | { | 318 | { |
319 | const uint64_t baadfood = GNUNET_ntohll (0xBAADF00DBAADF00DLL); | 319 | const uint64_t baadfood = GNUNET_ntohll(0xBAADF00DBAADF00DLL); |
320 | uint64_t *base = ptr; | 320 | uint64_t *base = ptr; |
321 | size_t s = M_SIZE (ptr); | 321 | size_t s = M_SIZE(ptr); |
322 | size_t i; | 322 | size_t i; |
323 | 323 | ||
324 | for (i = 0; i < s / 8; i++) | 324 | for (i = 0; i < s / 8; i++) |
325 | base[i] = baadfood; | 325 | base[i] = baadfood; |
326 | GNUNET_memcpy (&base[s / 8], &baadfood, s % 8); | 326 | GNUNET_memcpy(&base[s / 8], &baadfood, s % 8); |
327 | } | 327 | } |
328 | #endif | 328 | #endif |
329 | #endif | 329 | #endif |
330 | free (ptr); | 330 | free(ptr); |
331 | } | 331 | } |
332 | 332 | ||
333 | 333 | ||
@@ -340,26 +340,26 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) | |||
340 | * @return `strdup(@a str)` | 340 | * @return `strdup(@a str)` |
341 | */ | 341 | */ |
342 | char * | 342 | char * |
343 | GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) | 343 | GNUNET_xstrdup_(const char *str, const char *filename, int linenumber) |
344 | { | 344 | { |
345 | char *res; | 345 | char *res; |
346 | size_t slen; | 346 | size_t slen; |
347 | 347 | ||
348 | GNUNET_assert_at (str != NULL, filename, linenumber); | 348 | GNUNET_assert_at(str != NULL, filename, linenumber); |
349 | slen = strlen (str) + 1; | 349 | slen = strlen(str) + 1; |
350 | res = GNUNET_xmalloc_ (slen, filename, linenumber); | 350 | res = GNUNET_xmalloc_(slen, filename, linenumber); |
351 | GNUNET_memcpy (res, str, slen); | 351 | GNUNET_memcpy(res, str, slen); |
352 | return res; | 352 | return res; |
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
356 | #if ! HAVE_STRNLEN | 356 | #if !HAVE_STRNLEN |
357 | static size_t | 357 | static size_t |
358 | strnlen (const char *s, size_t n) | 358 | strnlen(const char *s, size_t n) |
359 | { | 359 | { |
360 | const char *e; | 360 | const char *e; |
361 | 361 | ||
362 | e = memchr (s, '\0', n); | 362 | e = memchr(s, '\0', n); |
363 | if (NULL == e) | 363 | if (NULL == e) |
364 | return n; | 364 | return n; |
365 | return e - s; | 365 | return e - s; |
@@ -377,19 +377,19 @@ strnlen (const char *s, size_t n) | |||
377 | * @return `strndup(@a str,@a len)` | 377 | * @return `strndup(@a str,@a len)` |
378 | */ | 378 | */ |
379 | char * | 379 | char * |
380 | GNUNET_xstrndup_ (const char *str, | 380 | GNUNET_xstrndup_(const char *str, |
381 | size_t len, | 381 | size_t len, |
382 | const char *filename, | 382 | const char *filename, |
383 | int linenumber) | 383 | int linenumber) |
384 | { | 384 | { |
385 | char *res; | 385 | char *res; |
386 | 386 | ||
387 | if (0 == len) | 387 | if (0 == len) |
388 | return GNUNET_strdup (""); | 388 | return GNUNET_strdup(""); |
389 | GNUNET_assert_at (NULL != str, filename, linenumber); | 389 | GNUNET_assert_at(NULL != str, filename, linenumber); |
390 | len = strnlen (str, len); | 390 | len = strnlen(str, len); |
391 | res = GNUNET_xmalloc_ (len + 1, filename, linenumber); | 391 | res = GNUNET_xmalloc_(len + 1, filename, linenumber); |
392 | GNUNET_memcpy (res, str, len); | 392 | GNUNET_memcpy(res, str, len); |
393 | /* res[len] = '\0'; 'malloc' zeros out anyway */ | 393 | /* res[len] = '\0'; 'malloc' zeros out anyway */ |
394 | return res; | 394 | return res; |
395 | } | 395 | } |
@@ -408,35 +408,35 @@ GNUNET_xstrndup_ (const char *str, | |||
408 | * @param linenumber where in the code was the call to GNUNET_array_grow() | 408 | * @param linenumber where in the code was the call to GNUNET_array_grow() |
409 | */ | 409 | */ |
410 | void | 410 | void |
411 | GNUNET_xgrow_ (void **old, | 411 | GNUNET_xgrow_(void **old, |
412 | size_t elementSize, | 412 | size_t elementSize, |
413 | unsigned int *oldCount, | 413 | unsigned int *oldCount, |
414 | unsigned int newCount, | 414 | unsigned int newCount, |
415 | const char *filename, | 415 | const char *filename, |
416 | int linenumber) | 416 | int linenumber) |
417 | { | 417 | { |
418 | void *tmp; | 418 | void *tmp; |
419 | size_t size; | 419 | size_t size; |
420 | 420 | ||
421 | GNUNET_assert_at (INT_MAX / elementSize > newCount, filename, linenumber); | 421 | GNUNET_assert_at(INT_MAX / elementSize > newCount, filename, linenumber); |
422 | size = newCount * elementSize; | 422 | size = newCount * elementSize; |
423 | if (0 == size) | 423 | if (0 == size) |
424 | { | 424 | { |
425 | tmp = NULL; | 425 | tmp = NULL; |
426 | } | 426 | } |
427 | else | 427 | else |
428 | { | ||
429 | tmp = GNUNET_xmalloc_ (size, filename, linenumber); | ||
430 | if (NULL != *old) | ||
431 | { | 428 | { |
432 | GNUNET_memcpy (tmp, *old, elementSize * GNUNET_MIN (*oldCount, newCount)); | 429 | tmp = GNUNET_xmalloc_(size, filename, linenumber); |
430 | if (NULL != *old) | ||
431 | { | ||
432 | GNUNET_memcpy(tmp, *old, elementSize * GNUNET_MIN(*oldCount, newCount)); | ||
433 | } | ||
433 | } | 434 | } |
434 | } | ||
435 | 435 | ||
436 | if (NULL != *old) | 436 | if (NULL != *old) |
437 | { | 437 | { |
438 | GNUNET_xfree_ (*old, filename, linenumber); | 438 | GNUNET_xfree_(*old, filename, linenumber); |
439 | } | 439 | } |
440 | *old = tmp; | 440 | *old = tmp; |
441 | *oldCount = newCount; | 441 | *oldCount = newCount; |
442 | } | 442 | } |
@@ -451,19 +451,19 @@ GNUNET_xgrow_ (void **old, | |||
451 | * @return number of bytes in `*@a buf`, excluding 0-termination | 451 | * @return number of bytes in `*@a buf`, excluding 0-termination |
452 | */ | 452 | */ |
453 | int | 453 | int |
454 | GNUNET_asprintf (char **buf, const char *format, ...) | 454 | GNUNET_asprintf(char **buf, const char *format, ...) |
455 | { | 455 | { |
456 | int ret; | 456 | int ret; |
457 | va_list args; | 457 | va_list args; |
458 | 458 | ||
459 | va_start (args, format); | 459 | va_start(args, format); |
460 | ret = vsnprintf (NULL, 0, format, args); | 460 | ret = vsnprintf(NULL, 0, format, args); |
461 | va_end (args); | 461 | va_end(args); |
462 | GNUNET_assert (ret >= 0); | 462 | GNUNET_assert(ret >= 0); |
463 | *buf = GNUNET_malloc (ret + 1); | 463 | *buf = GNUNET_malloc(ret + 1); |
464 | va_start (args, format); | 464 | va_start(args, format); |
465 | ret = vsprintf (*buf, format, args); | 465 | ret = vsprintf(*buf, format, args); |
466 | va_end (args); | 466 | va_end(args); |
467 | return ret; | 467 | return ret; |
468 | } | 468 | } |
469 | 469 | ||
@@ -478,15 +478,15 @@ GNUNET_asprintf (char **buf, const char *format, ...) | |||
478 | * @return number of bytes written to buf or negative value on error | 478 | * @return number of bytes written to buf or negative value on error |
479 | */ | 479 | */ |
480 | int | 480 | int |
481 | GNUNET_snprintf (char *buf, size_t size, const char *format, ...) | 481 | GNUNET_snprintf(char *buf, size_t size, const char *format, ...) |
482 | { | 482 | { |
483 | int ret; | 483 | int ret; |
484 | va_list args; | 484 | va_list args; |
485 | 485 | ||
486 | va_start (args, format); | 486 | va_start(args, format); |
487 | ret = vsnprintf (buf, size, format, args); | 487 | ret = vsnprintf(buf, size, format, args); |
488 | va_end (args); | 488 | va_end(args); |
489 | GNUNET_assert ((ret >= 0) && (((size_t) ret) < size)); | 489 | GNUNET_assert((ret >= 0) && (((size_t)ret) < size)); |
490 | return ret; | 490 | return ret; |
491 | } | 491 | } |
492 | 492 | ||
@@ -498,15 +498,15 @@ GNUNET_snprintf (char *buf, size_t size, const char *format, ...) | |||
498 | * @return duplicate of the message | 498 | * @return duplicate of the message |
499 | */ | 499 | */ |
500 | struct GNUNET_MessageHeader * | 500 | struct GNUNET_MessageHeader * |
501 | GNUNET_copy_message (const struct GNUNET_MessageHeader *msg) | 501 | GNUNET_copy_message(const struct GNUNET_MessageHeader *msg) |
502 | { | 502 | { |
503 | struct GNUNET_MessageHeader *ret; | 503 | struct GNUNET_MessageHeader *ret; |
504 | uint16_t msize; | 504 | uint16_t msize; |
505 | 505 | ||
506 | msize = ntohs (msg->size); | 506 | msize = ntohs(msg->size); |
507 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); | 507 | GNUNET_assert(msize >= sizeof(struct GNUNET_MessageHeader)); |
508 | ret = GNUNET_malloc (msize); | 508 | ret = GNUNET_malloc(msize); |
509 | GNUNET_memcpy (ret, msg, msize); | 509 | GNUNET_memcpy(ret, msg, msize); |
510 | return ret; | 510 | return ret; |
511 | } | 511 | } |
512 | 512 | ||