diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/bio.c | 69 | ||||
-rw-r--r-- | src/util/client.c | 3 | ||||
-rw-r--r-- | src/util/common_allocation.c | 27 | ||||
-rw-r--r-- | src/util/configuration.c | 38 | ||||
-rw-r--r-- | src/util/container_bloomfilter.c | 60 | ||||
-rw-r--r-- | src/util/test_service.c | 27 |
6 files changed, 165 insertions, 59 deletions
diff --git a/src/util/bio.c b/src/util/bio.c index 08e30dc01..816917a22 100644 --- a/src/util/bio.c +++ b/src/util/bio.c | |||
@@ -162,15 +162,19 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | |||
162 | { | 162 | { |
163 | if (min > len - pos) | 163 | if (min > len - pos) |
164 | min = len - pos; | 164 | min = len - pos; |
165 | GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min); | 165 | GNUNET_memcpy (&dst[pos], |
166 | &h->buffer[h->pos], | ||
167 | min); | ||
166 | h->pos += min; | 168 | h->pos += min; |
167 | pos += min; | 169 | pos += min; |
168 | } | 170 | } |
169 | if (pos == len) | 171 | if (pos == len) |
170 | return GNUNET_OK; /* done! */ | 172 | return GNUNET_OK; /* done! */ |
171 | GNUNET_assert (h->have == h->pos); | 173 | GNUNET_assert (((off_t) h->have) == h->pos); |
172 | /* fill buffer */ | 174 | /* fill buffer */ |
173 | ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size); | 175 | ret = GNUNET_DISK_file_read (h->fd, |
176 | h->buffer, | ||
177 | h->size); | ||
174 | if (-1 == ret) | 178 | if (-1 == ret) |
175 | { | 179 | { |
176 | GNUNET_asprintf (&h->emsg, | 180 | GNUNET_asprintf (&h->emsg, |
@@ -287,7 +291,9 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
287 | char *buf; | 291 | char *buf; |
288 | struct GNUNET_CONTAINER_MetaData *meta; | 292 | struct GNUNET_CONTAINER_MetaData *meta; |
289 | 293 | ||
290 | if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK) | 294 | if (GNUNET_OK != |
295 | GNUNET_BIO_read_int32 (h, | ||
296 | (int32_t *) & size)) | ||
291 | return GNUNET_SYSERR; | 297 | return GNUNET_SYSERR; |
292 | if (size == 0) | 298 | if (size == 0) |
293 | { | 299 | { |
@@ -298,20 +304,29 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
298 | { | 304 | { |
299 | GNUNET_asprintf (&h->emsg, | 305 | GNUNET_asprintf (&h->emsg, |
300 | _("Serialized metadata `%s' larger than allowed (%u>%u)"), | 306 | _("Serialized metadata `%s' larger than allowed (%u>%u)"), |
301 | what, size, MAX_META_DATA); | 307 | what, |
308 | size, | ||
309 | MAX_META_DATA); | ||
302 | return GNUNET_SYSERR; | 310 | return GNUNET_SYSERR; |
303 | } | 311 | } |
304 | buf = GNUNET_malloc (size); | 312 | buf = GNUNET_malloc (size); |
305 | if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size)) | 313 | if (GNUNET_OK != |
314 | GNUNET_BIO_read (h, | ||
315 | what, | ||
316 | buf, | ||
317 | size)) | ||
306 | { | 318 | { |
307 | GNUNET_free (buf); | 319 | GNUNET_free (buf); |
308 | return GNUNET_SYSERR; | 320 | return GNUNET_SYSERR; |
309 | } | 321 | } |
310 | meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size); | 322 | meta = GNUNET_CONTAINER_meta_data_deserialize (buf, |
311 | if (meta == NULL) | 323 | size); |
324 | if (NULL == meta) | ||
312 | { | 325 | { |
313 | GNUNET_free (buf); | 326 | GNUNET_free (buf); |
314 | GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what); | 327 | GNUNET_asprintf (&h->emsg, |
328 | _("Metadata `%s' failed to deserialize"), | ||
329 | what); | ||
315 | return GNUNET_SYSERR; | 330 | return GNUNET_SYSERR; |
316 | } | 331 | } |
317 | GNUNET_free (buf); | 332 | GNUNET_free (buf); |
@@ -330,12 +345,19 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, | |||
330 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 345 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
331 | */ | 346 | */ |
332 | int | 347 | int |
333 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, | 348 | GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, |
334 | int line, int32_t * i) | 349 | const char *file, |
350 | int line, | ||
351 | int32_t * i) | ||
335 | { | 352 | { |
336 | int32_t big; | 353 | int32_t big; |
337 | 354 | ||
338 | if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t))) | 355 | if (GNUNET_OK != |
356 | GNUNET_BIO_read_fn (h, | ||
357 | file, | ||
358 | line, | ||
359 | &big, | ||
360 | sizeof (int32_t))) | ||
339 | return GNUNET_SYSERR; | 361 | return GNUNET_SYSERR; |
340 | *i = ntohl (big); | 362 | *i = ntohl (big); |
341 | return GNUNET_OK; | 363 | return GNUNET_OK; |
@@ -359,7 +381,12 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, | |||
359 | { | 381 | { |
360 | int64_t big; | 382 | int64_t big; |
361 | 383 | ||
362 | if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t))) | 384 | if (GNUNET_OK != |
385 | GNUNET_BIO_read_fn (h, | ||
386 | file, | ||
387 | line, | ||
388 | &big, | ||
389 | sizeof (int64_t))) | ||
363 | return GNUNET_SYSERR; | 390 | return GNUNET_SYSERR; |
364 | *i = GNUNET_ntohll (big); | 391 | *i = GNUNET_ntohll (big); |
365 | return GNUNET_OK; | 392 | return GNUNET_OK; |
@@ -432,7 +459,8 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) | |||
432 | int ret; | 459 | int ret; |
433 | 460 | ||
434 | ret = GNUNET_SYSERR; | 461 | ret = GNUNET_SYSERR; |
435 | if ( (NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) ) | 462 | if ( (NULL != h->fd) && |
463 | (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) ) | ||
436 | GNUNET_DISK_file_close (h->fd); | 464 | GNUNET_DISK_file_close (h->fd); |
437 | GNUNET_free (h); | 465 | GNUNET_free (h); |
438 | return ret; | 466 | return ret; |
@@ -451,8 +479,10 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | |||
451 | { | 479 | { |
452 | ssize_t ret; | 480 | ssize_t ret; |
453 | 481 | ||
454 | ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); | 482 | ret = GNUNET_DISK_file_write (h->fd, |
455 | if (ret != h->have) | 483 | h->buffer, |
484 | h->have); | ||
485 | if (ret != (ssize_t) h->have) | ||
456 | { | 486 | { |
457 | GNUNET_DISK_file_close (h->fd); | 487 | GNUNET_DISK_file_close (h->fd); |
458 | h->fd = NULL; | 488 | h->fd = NULL; |
@@ -472,7 +502,8 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) | |||
472 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 502 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
473 | */ | 503 | */ |
474 | int | 504 | int |
475 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, | 505 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, |
506 | const void *buffer, | ||
476 | size_t n) | 507 | size_t n) |
477 | { | 508 | { |
478 | const char *src = buffer; | 509 | const char *src = buffer; |
@@ -488,7 +519,9 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, | |||
488 | min = h->size - h->have; | 519 | min = h->size - h->have; |
489 | if (min > n - pos) | 520 | if (min > n - pos) |
490 | min = n - pos; | 521 | min = n - pos; |
491 | GNUNET_memcpy (&h->buffer[h->have], &src[pos], min); | 522 | GNUNET_memcpy (&h->buffer[h->have], |
523 | &src[pos], | ||
524 | min); | ||
492 | pos += min; | 525 | pos += min; |
493 | h->have += min; | 526 | h->have += min; |
494 | if (pos == n) | 527 | if (pos == n) |
diff --git a/src/util/client.c b/src/util/client.c index e5bf7e176..7a718fc8d 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -377,6 +377,7 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, | |||
377 | { | 377 | { |
378 | struct ClientState *cstate = impl_state; | 378 | struct ClientState *cstate = impl_state; |
379 | 379 | ||
380 | (void) mq; | ||
380 | if (GNUNET_SYSERR == cstate->in_destroy) | 381 | if (GNUNET_SYSERR == cstate->in_destroy) |
381 | { | 382 | { |
382 | /* defer destruction */ | 383 | /* defer destruction */ |
@@ -814,6 +815,7 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq, | |||
814 | { | 815 | { |
815 | struct ClientState *cstate = impl_state; | 816 | struct ClientState *cstate = impl_state; |
816 | 817 | ||
818 | (void) mq; | ||
817 | /* only one message at a time allowed */ | 819 | /* only one message at a time allowed */ |
818 | GNUNET_assert (NULL == cstate->msg); | 820 | GNUNET_assert (NULL == cstate->msg); |
819 | GNUNET_assert (NULL == cstate->send_task); | 821 | GNUNET_assert (NULL == cstate->send_task); |
@@ -845,6 +847,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, | |||
845 | { | 847 | { |
846 | struct ClientState *cstate = impl_state; | 848 | struct ClientState *cstate = impl_state; |
847 | 849 | ||
850 | (void) mq; | ||
848 | GNUNET_assert (NULL != cstate->msg); | 851 | GNUNET_assert (NULL != cstate->msg); |
849 | GNUNET_assert (0 == cstate->msg_off); | 852 | GNUNET_assert (0 == cstate->msg_off); |
850 | cstate->msg = NULL; | 853 | cstate->msg = NULL; |
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 737584815..be2538c3f 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c | |||
@@ -100,8 +100,11 @@ GNUNET_xmalloc_ (size_t size, | |||
100 | * @return allocated memory, never NULL | 100 | * @return allocated memory, never NULL |
101 | */ | 101 | */ |
102 | void ** | 102 | void ** |
103 | GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, | 103 | GNUNET_xnew_array_2d_ (size_t n, |
104 | const char *filename, int linenumber) | 104 | size_t m, |
105 | size_t elementSize, | ||
106 | const char *filename, | ||
107 | int linenumber) | ||
105 | { | 108 | { |
106 | /* use char pointer internally to avoid void pointer arithmetic warnings */ | 109 | /* use char pointer internally to avoid void pointer arithmetic warnings */ |
107 | char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ | 110 | char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */ |
@@ -218,6 +221,8 @@ GNUNET_xmalloc_unchecked_ (size_t size, | |||
218 | { | 221 | { |
219 | void *result; | 222 | void *result; |
220 | 223 | ||
224 | (void) filename; | ||
225 | (void) linenumber; | ||
221 | #ifdef W32_MEM_LIMIT | 226 | #ifdef W32_MEM_LIMIT |
222 | size += sizeof (size_t); | 227 | size += sizeof (size_t); |
223 | if (mem_used + size > W32_MEM_LIMIT) | 228 | if (mem_used + size > W32_MEM_LIMIT) |
@@ -256,6 +261,9 @@ GNUNET_xrealloc_ (void *ptr, | |||
256 | const char *filename, | 261 | const char *filename, |
257 | int linenumber) | 262 | int linenumber) |
258 | { | 263 | { |
264 | (void) filename; | ||
265 | (void) linenumber; | ||
266 | |||
259 | #ifdef W32_MEM_LIMIT | 267 | #ifdef W32_MEM_LIMIT |
260 | n += sizeof (size_t); | 268 | n += sizeof (size_t); |
261 | ptr = &((size_t *) ptr)[-1]; | 269 | ptr = &((size_t *) ptr)[-1]; |
@@ -264,7 +272,8 @@ GNUNET_xrealloc_ (void *ptr, | |||
264 | ptr = realloc (ptr, n); | 272 | ptr = realloc (ptr, n); |
265 | if ((NULL == ptr) && (n > 0)) | 273 | if ((NULL == ptr) && (n > 0)) |
266 | { | 274 | { |
267 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); | 275 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, |
276 | "realloc"); | ||
268 | GNUNET_assert (0); | 277 | GNUNET_assert (0); |
269 | } | 278 | } |
270 | #ifdef W32_MEM_LIMIT | 279 | #ifdef W32_MEM_LIMIT |
@@ -501,9 +510,13 @@ GNUNET_snprintf (char *buf, | |||
501 | va_list args; | 510 | va_list args; |
502 | 511 | ||
503 | va_start (args, format); | 512 | va_start (args, format); |
504 | ret = VSNPRINTF (buf, size, format, args); | 513 | ret = VSNPRINTF (buf, |
514 | size, | ||
515 | format, | ||
516 | args); | ||
505 | va_end (args); | 517 | va_end (args); |
506 | GNUNET_assert (ret < size); | 518 | GNUNET_assert ( (ret >= 0) && |
519 | (((size_t) ret) < size) ); | ||
507 | return ret; | 520 | return ret; |
508 | } | 521 | } |
509 | 522 | ||
@@ -523,7 +536,9 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg) | |||
523 | msize = ntohs (msg->size); | 536 | msize = ntohs (msg->size); |
524 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); | 537 | GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); |
525 | ret = GNUNET_malloc (msize); | 538 | ret = GNUNET_malloc (msize); |
526 | GNUNET_memcpy (ret, msg, msize); | 539 | GNUNET_memcpy (ret, |
540 | msg, | ||
541 | msize); | ||
527 | return ret; | 542 | return ret; |
528 | } | 543 | } |
529 | 544 | ||
diff --git a/src/util/configuration.c b/src/util/configuration.c index f63903b4e..7f1d98902 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -324,6 +324,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
324 | char *endsep; | 324 | char *endsep; |
325 | int dirty; | 325 | int dirty; |
326 | int ret; | 326 | int ret; |
327 | ssize_t sret; | ||
327 | 328 | ||
328 | fn = GNUNET_STRINGS_filename_expand (filename); | 329 | fn = GNUNET_STRINGS_filename_expand (filename); |
329 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 330 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -333,7 +334,10 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
333 | return GNUNET_SYSERR; | 334 | return GNUNET_SYSERR; |
334 | dirty = cfg->dirty; /* back up value! */ | 335 | dirty = cfg->dirty; /* back up value! */ |
335 | if (GNUNET_SYSERR == | 336 | if (GNUNET_SYSERR == |
336 | GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES)) | 337 | GNUNET_DISK_file_size (fn, |
338 | &fs64, | ||
339 | GNUNET_YES, | ||
340 | GNUNET_YES)) | ||
337 | { | 341 | { |
338 | LOG (GNUNET_ERROR_TYPE_WARNING, | 342 | LOG (GNUNET_ERROR_TYPE_WARNING, |
339 | "Error while determining the file size of `%s'\n", | 343 | "Error while determining the file size of `%s'\n", |
@@ -349,7 +353,11 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
349 | } | 353 | } |
350 | fs = fs64; | 354 | fs = fs64; |
351 | mem = GNUNET_malloc (fs); | 355 | mem = GNUNET_malloc (fs); |
352 | if (fs != GNUNET_DISK_fn_read (fn, mem, fs)) | 356 | sret = GNUNET_DISK_fn_read (fn, |
357 | mem, | ||
358 | fs); | ||
359 | if ( (sret < 0) || | ||
360 | (fs != (size_t) sret) ) | ||
353 | { | 361 | { |
354 | LOG (GNUNET_ERROR_TYPE_WARNING, | 362 | LOG (GNUNET_ERROR_TYPE_WARNING, |
355 | _("Error while reading file `%s'\n"), | 363 | _("Error while reading file `%s'\n"), |
@@ -495,6 +503,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
495 | char *fn; | 503 | char *fn; |
496 | char *cfg_buf; | 504 | char *cfg_buf; |
497 | size_t size; | 505 | size_t size; |
506 | ssize_t sret; | ||
498 | 507 | ||
499 | fn = GNUNET_STRINGS_filename_expand (filename); | 508 | fn = GNUNET_STRINGS_filename_expand (filename); |
500 | if (fn == NULL) | 509 | if (fn == NULL) |
@@ -505,11 +514,13 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
505 | return GNUNET_SYSERR; | 514 | return GNUNET_SYSERR; |
506 | } | 515 | } |
507 | cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); | 516 | cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); |
508 | if (size != GNUNET_DISK_fn_write (fn, cfg_buf, size, | 517 | sret = GNUNET_DISK_fn_write (fn, cfg_buf, size, |
509 | GNUNET_DISK_PERM_USER_READ | 518 | GNUNET_DISK_PERM_USER_READ |
510 | | GNUNET_DISK_PERM_USER_WRITE | 519 | | GNUNET_DISK_PERM_USER_WRITE |
511 | | GNUNET_DISK_PERM_GROUP_READ | 520 | | GNUNET_DISK_PERM_GROUP_READ |
512 | | GNUNET_DISK_PERM_GROUP_WRITE)) | 521 | | GNUNET_DISK_PERM_GROUP_WRITE); |
522 | if ( (sret < 0) || | ||
523 | (size != (size_t) sret) ) | ||
513 | { | 524 | { |
514 | GNUNET_free (fn); | 525 | GNUNET_free (fn); |
515 | GNUNET_free (cfg_buf); | 526 | GNUNET_free (cfg_buf); |
@@ -858,13 +869,20 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
858 | */ | 869 | */ |
859 | void | 870 | void |
860 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | 871 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, |
861 | const char *section, const char *option, | 872 | const char *section, |
873 | const char *option, | ||
862 | unsigned long long number) | 874 | unsigned long long number) |
863 | { | 875 | { |
864 | char s[64]; | 876 | char s[64]; |
865 | 877 | ||
866 | GNUNET_snprintf (s, 64, "%llu", number); | 878 | GNUNET_snprintf (s, |
867 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); | 879 | 64, |
880 | "%llu", | ||
881 | number); | ||
882 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
883 | section, | ||
884 | option, | ||
885 | s); | ||
868 | } | 886 | } |
869 | 887 | ||
870 | 888 | ||
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index aedca232d..95c05b9d7 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012 GNUnet e.V. | 3 | Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -513,10 +513,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
513 | GNUNET_free (bf); | 513 | GNUNET_free (bf); |
514 | return NULL; | 514 | return NULL; |
515 | } | 515 | } |
516 | if (fsize == 0) | 516 | if (0 == fsize) |
517 | { | 517 | { |
518 | /* found existing empty file, just overwrite */ | 518 | /* found existing empty file, just overwrite */ |
519 | if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL)) | 519 | if (GNUNET_OK != |
520 | make_empty_file (bf->fh, size * 4LL)) | ||
520 | { | 521 | { |
521 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 522 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
522 | "write"); | 523 | "write"); |
@@ -525,7 +526,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
525 | return NULL; | 526 | return NULL; |
526 | } | 527 | } |
527 | } | 528 | } |
528 | else if (fsize != size * 4LL) | 529 | else if (fsize != ((off_t) size) * 4LL) |
529 | { | 530 | { |
530 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 531 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
531 | _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"), | 532 | _("Size of file on disk is incorrect for this Bloom filter (want %llu, have %llu)\n"), |
@@ -563,9 +564,9 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
563 | bf->filename = GNUNET_strdup (filename); | 564 | bf->filename = GNUNET_strdup (filename); |
564 | /* Alloc block */ | 565 | /* Alloc block */ |
565 | bf->bitArray = GNUNET_malloc_large (size); | 566 | bf->bitArray = GNUNET_malloc_large (size); |
566 | if (bf->bitArray == NULL) | 567 | if (NULL == bf->bitArray) |
567 | { | 568 | { |
568 | if (bf->fh != NULL) | 569 | if (NULL != bf->fh) |
569 | GNUNET_DISK_file_close (bf->fh); | 570 | GNUNET_DISK_file_close (bf->fh); |
570 | GNUNET_free (bf->filename); | 571 | GNUNET_free (bf->filename); |
571 | GNUNET_free (bf); | 572 | GNUNET_free (bf); |
@@ -578,14 +579,18 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, | |||
578 | /* Read from the file what bits we can */ | 579 | /* Read from the file what bits we can */ |
579 | rbuff = GNUNET_malloc (BUFFSIZE); | 580 | rbuff = GNUNET_malloc (BUFFSIZE); |
580 | pos = 0; | 581 | pos = 0; |
581 | while (pos < size * 8LL) | 582 | while (pos < ((off_t) size) * 8LL) |
582 | { | 583 | { |
583 | int res; | 584 | int res; |
584 | 585 | ||
585 | res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); | 586 | res = GNUNET_DISK_file_read (bf->fh, |
587 | rbuff, | ||
588 | BUFFSIZE); | ||
586 | if (res == -1) | 589 | if (res == -1) |
587 | { | 590 | { |
588 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename); | 591 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
592 | "read", | ||
593 | bf->filename); | ||
589 | GNUNET_free (rbuff); | 594 | GNUNET_free (rbuff); |
590 | GNUNET_free (bf->filename); | 595 | GNUNET_free (bf->filename); |
591 | GNUNET_DISK_file_close (bf->fh); | 596 | GNUNET_DISK_file_close (bf->fh); |
@@ -713,11 +718,11 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf) | |||
713 | * | 718 | * |
714 | * @param e the element | 719 | * @param e the element |
715 | * @param bf the filter | 720 | * @param bf the filter |
716 | * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not | 721 | * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not |
717 | */ | 722 | */ |
718 | int | 723 | int |
719 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter | 724 | GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf, |
720 | *bf, const struct GNUNET_HashCode * e) | 725 | const struct GNUNET_HashCode * e) |
721 | { | 726 | { |
722 | int res; | 727 | int res; |
723 | 728 | ||
@@ -757,7 +762,8 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
757 | */ | 762 | */ |
758 | int | 763 | int |
759 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | 764 | GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, |
760 | const char *data, size_t size) | 765 | const char *data, |
766 | size_t size) | ||
761 | { | 767 | { |
762 | unsigned int i; | 768 | unsigned int i; |
763 | unsigned int n; | 769 | unsigned int n; |
@@ -791,8 +797,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
791 | */ | 797 | */ |
792 | int | 798 | int |
793 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | 799 | GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, |
794 | const struct GNUNET_CONTAINER_BloomFilter | 800 | const struct GNUNET_CONTAINER_BloomFilter *to_or) |
795 | *to_or) | ||
796 | { | 801 | { |
797 | unsigned int i; | 802 | unsigned int i; |
798 | unsigned int n; | 803 | unsigned int n; |
@@ -828,13 +833,16 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
828 | */ | 833 | */ |
829 | void | 834 | void |
830 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | 835 | GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, |
831 | const struct GNUNET_HashCode * e) | 836 | const struct GNUNET_HashCode *e) |
832 | { | 837 | { |
833 | if (NULL == bf) | 838 | if (NULL == bf) |
834 | return; | 839 | return; |
835 | if (bf->filename == NULL) | 840 | if (NULL == bf->filename) |
836 | return; | 841 | return; |
837 | iterateBits (bf, &decrementBitCallback, bf, e); | 842 | iterateBits (bf, |
843 | &decrementBitCallback, | ||
844 | bf, | ||
845 | e); | ||
838 | } | 846 | } |
839 | 847 | ||
840 | /** | 848 | /** |
@@ -851,7 +859,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
851 | void | 859 | void |
852 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | 860 | GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, |
853 | GNUNET_CONTAINER_HashCodeIterator iterator, | 861 | GNUNET_CONTAINER_HashCodeIterator iterator, |
854 | void *iterator_cls, size_t size, | 862 | void *iterator_cls, |
863 | size_t size, | ||
855 | unsigned int k) | 864 | unsigned int k) |
856 | { | 865 | { |
857 | struct GNUNET_HashCode hc; | 866 | struct GNUNET_HashCode hc; |
@@ -862,13 +871,16 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, | |||
862 | while (i < size) | 871 | while (i < size) |
863 | i *= 2; | 872 | i *= 2; |
864 | size = i; /* make sure it's a power of 2 */ | 873 | size = i; /* make sure it's a power of 2 */ |
865 | 874 | bf->addressesPerElement = k; | |
866 | bf->bitArraySize = size; | 875 | bf->bitArraySize = size; |
867 | bf->bitArray = GNUNET_malloc (size); | 876 | bf->bitArray = GNUNET_malloc (size); |
868 | if (bf->filename != NULL) | 877 | if (NULL != bf->filename) |
869 | make_empty_file (bf->fh, bf->bitArraySize * 4LL); | 878 | make_empty_file (bf->fh, |
870 | while (GNUNET_YES == iterator (iterator_cls, &hc)) | 879 | bf->bitArraySize * 4LL); |
871 | GNUNET_CONTAINER_bloomfilter_add (bf, &hc); | 880 | while (GNUNET_YES == iterator (iterator_cls, |
881 | &hc)) | ||
882 | GNUNET_CONTAINER_bloomfilter_add (bf, | ||
883 | &hc); | ||
872 | } | 884 | } |
873 | 885 | ||
874 | /* end of container_bloomfilter.c */ | 886 | /* end of container_bloomfilter.c */ |
diff --git a/src/util/test_service.c b/src/util/test_service.c index 1567c97ce..3ffacb0a9 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -30,10 +30,17 @@ | |||
30 | */ | 30 | */ |
31 | #define MY_TYPE 256 | 31 | #define MY_TYPE 256 |
32 | 32 | ||
33 | #define TIMEOUT GNUNET_TIME_UNIT_SECONDS | ||
34 | |||
33 | static int global_ret = 1; | 35 | static int global_ret = 1; |
34 | 36 | ||
35 | static struct GNUNET_MQ_Handle *mq; | 37 | static struct GNUNET_MQ_Handle *mq; |
36 | 38 | ||
39 | /** | ||
40 | * Timeout task. | ||
41 | */ | ||
42 | static struct GNUNET_SCHEDULER_Task *tt; | ||
43 | |||
37 | 44 | ||
38 | static void | 45 | static void |
39 | handle_recv (void *cls, | 46 | handle_recv (void *cls, |
@@ -86,10 +93,24 @@ disconnect_cb (void *cls, | |||
86 | { | 93 | { |
87 | GNUNET_SCHEDULER_shutdown (); | 94 | GNUNET_SCHEDULER_shutdown (); |
88 | global_ret = 0; | 95 | global_ret = 0; |
96 | if (NULL != tt) | ||
97 | { | ||
98 | GNUNET_SCHEDULER_cancel (tt); | ||
99 | tt = NULL; | ||
100 | } | ||
89 | } | 101 | } |
90 | } | 102 | } |
91 | 103 | ||
92 | 104 | ||
105 | static void | ||
106 | timeout_task (void *cls) | ||
107 | { | ||
108 | tt = NULL; | ||
109 | global_ret = 33; | ||
110 | GNUNET_SCHEDULER_shutdown (); | ||
111 | } | ||
112 | |||
113 | |||
93 | /** | 114 | /** |
94 | * Initialization function of the service. Starts | 115 | * Initialization function of the service. Starts |
95 | * a client to connect to the service. | 116 | * a client to connect to the service. |
@@ -106,7 +127,11 @@ service_init (void *cls, | |||
106 | const char *service_name = cls; | 127 | const char *service_name = cls; |
107 | struct GNUNET_MQ_Envelope *env; | 128 | struct GNUNET_MQ_Envelope *env; |
108 | struct GNUNET_MessageHeader *msg; | 129 | struct GNUNET_MessageHeader *msg; |
109 | 130 | ||
131 | GNUNET_assert (NULL == tt); | ||
132 | tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
133 | &timeout_task, | ||
134 | NULL); | ||
110 | mq = GNUNET_CLIENT_connect (cfg, | 135 | mq = GNUNET_CLIENT_connect (cfg, |
111 | service_name, | 136 | service_name, |
112 | NULL, | 137 | NULL, |