aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/util/bio.c69
-rw-r--r--src/util/client.c3
-rw-r--r--src/util/common_allocation.c27
-rw-r--r--src/util/configuration.c38
-rw-r--r--src/util/container_bloomfilter.c60
-rw-r--r--src/util/test_service.c27
6 files changed, 165 insertions, 59 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index 08e30dc01a..816917a223 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -162,15 +162,19 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
{
if (min > len - pos)
min = len - pos;
- GNUNET_memcpy (&dst[pos], &h->buffer[h->pos], min);
+ GNUNET_memcpy (&dst[pos],
+ &h->buffer[h->pos],
+ min);
h->pos += min;
pos += min;
}
if (pos == len)
return GNUNET_OK; /* done! */
- GNUNET_assert (h->have == h->pos);
+ GNUNET_assert (((off_t) h->have) == h->pos);
/* fill buffer */
- ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
+ ret = GNUNET_DISK_file_read (h->fd,
+ h->buffer,
+ h->size);
if (-1 == ret)
{
GNUNET_asprintf (&h->emsg,
@@ -287,7 +291,9 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
char *buf;
struct GNUNET_CONTAINER_MetaData *meta;
- if (GNUNET_BIO_read_int32 (h, (int32_t *) & size) != GNUNET_OK)
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_int32 (h,
+ (int32_t *) & size))
return GNUNET_SYSERR;
if (size == 0)
{
@@ -298,20 +304,29 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
{
GNUNET_asprintf (&h->emsg,
_("Serialized metadata `%s' larger than allowed (%u>%u)"),
- what, size, MAX_META_DATA);
+ what,
+ size,
+ MAX_META_DATA);
return GNUNET_SYSERR;
}
buf = GNUNET_malloc (size);
- if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
+ if (GNUNET_OK !=
+ GNUNET_BIO_read (h,
+ what,
+ buf,
+ size))
{
GNUNET_free (buf);
return GNUNET_SYSERR;
}
- meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
- if (meta == NULL)
+ meta = GNUNET_CONTAINER_meta_data_deserialize (buf,
+ size);
+ if (NULL == meta)
{
GNUNET_free (buf);
- GNUNET_asprintf (&h->emsg, _("Metadata `%s' failed to deserialize"), what);
+ GNUNET_asprintf (&h->emsg,
+ _("Metadata `%s' failed to deserialize"),
+ what);
return GNUNET_SYSERR;
}
GNUNET_free (buf);
@@ -330,12 +345,19 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file,
- int line, int32_t * i)
+GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
+ const char *file,
+ int line,
+ int32_t * i)
{
int32_t big;
- if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int32_t)))
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_fn (h,
+ file,
+ line,
+ &big,
+ sizeof (int32_t)))
return GNUNET_SYSERR;
*i = ntohl (big);
return GNUNET_OK;
@@ -359,7 +381,12 @@ GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
{
int64_t big;
- if (GNUNET_OK != GNUNET_BIO_read_fn (h, file, line, &big, sizeof (int64_t)))
+ if (GNUNET_OK !=
+ GNUNET_BIO_read_fn (h,
+ file,
+ line,
+ &big,
+ sizeof (int64_t)))
return GNUNET_SYSERR;
*i = GNUNET_ntohll (big);
return GNUNET_OK;
@@ -432,7 +459,8 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
int ret;
ret = GNUNET_SYSERR;
- if ( (NULL != h->fd) && (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
+ if ( (NULL != h->fd) &&
+ (GNUNET_OK == (ret = GNUNET_BIO_flush (h))) )
GNUNET_DISK_file_close (h->fd);
GNUNET_free (h);
return ret;
@@ -451,8 +479,10 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
{
ssize_t ret;
- ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
- if (ret != h->have)
+ ret = GNUNET_DISK_file_write (h->fd,
+ h->buffer,
+ h->have);
+ if (ret != (ssize_t) h->have)
{
GNUNET_DISK_file_close (h->fd);
h->fd = NULL;
@@ -472,7 +502,8 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
int
-GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
+GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
+ const void *buffer,
size_t n)
{
const char *src = buffer;
@@ -488,7 +519,9 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer,
min = h->size - h->have;
if (min > n - pos)
min = n - pos;
- GNUNET_memcpy (&h->buffer[h->have], &src[pos], min);
+ GNUNET_memcpy (&h->buffer[h->have],
+ &src[pos],
+ min);
pos += min;
h->have += min;
if (pos == n)
diff --git a/src/util/client.c b/src/util/client.c
index e5bf7e1769..7a718fc8d4 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -377,6 +377,7 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
{
struct ClientState *cstate = impl_state;
+ (void) mq;
if (GNUNET_SYSERR == cstate->in_destroy)
{
/* defer destruction */
@@ -814,6 +815,7 @@ connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
{
struct ClientState *cstate = impl_state;
+ (void) mq;
/* only one message at a time allowed */
GNUNET_assert (NULL == cstate->msg);
GNUNET_assert (NULL == cstate->send_task);
@@ -845,6 +847,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
{
struct ClientState *cstate = impl_state;
+ (void) mq;
GNUNET_assert (NULL != cstate->msg);
GNUNET_assert (0 == cstate->msg_off);
cstate->msg = NULL;
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 7375848155..be2538c3f4 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -100,8 +100,11 @@ GNUNET_xmalloc_ (size_t size,
* @return allocated memory, never NULL
*/
void **
-GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize,
- const char *filename, int linenumber)
+GNUNET_xnew_array_2d_ (size_t n,
+ size_t m,
+ size_t elementSize,
+ const char *filename,
+ int linenumber)
{
/* use char pointer internally to avoid void pointer arithmetic warnings */
char **ret = GNUNET_xmalloc_ (n * sizeof (void *) + /* 1. dim header */
@@ -218,6 +221,8 @@ GNUNET_xmalloc_unchecked_ (size_t size,
{
void *result;
+ (void) filename;
+ (void) linenumber;
#ifdef W32_MEM_LIMIT
size += sizeof (size_t);
if (mem_used + size > W32_MEM_LIMIT)
@@ -256,6 +261,9 @@ GNUNET_xrealloc_ (void *ptr,
const char *filename,
int linenumber)
{
+ (void) filename;
+ (void) linenumber;
+
#ifdef W32_MEM_LIMIT
n += sizeof (size_t);
ptr = &((size_t *) ptr)[-1];
@@ -264,7 +272,8 @@ GNUNET_xrealloc_ (void *ptr,
ptr = realloc (ptr, n);
if ((NULL == ptr) && (n > 0))
{
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
+ LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+ "realloc");
GNUNET_assert (0);
}
#ifdef W32_MEM_LIMIT
@@ -501,9 +510,13 @@ GNUNET_snprintf (char *buf,
va_list args;
va_start (args, format);
- ret = VSNPRINTF (buf, size, format, args);
+ ret = VSNPRINTF (buf,
+ size,
+ format,
+ args);
va_end (args);
- GNUNET_assert (ret < size);
+ GNUNET_assert ( (ret >= 0) &&
+ (((size_t) ret) < size) );
return ret;
}
@@ -523,7 +536,9 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
msize = ntohs (msg->size);
GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
ret = GNUNET_malloc (msize);
- GNUNET_memcpy (ret, msg, msize);
+ GNUNET_memcpy (ret,
+ msg,
+ msize);
return ret;
}
diff --git a/src/util/configuration.c b/src/util/configuration.c
index f63903b4e9..7f1d98902a 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -324,6 +324,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
char *endsep;
int dirty;
int ret;
+ ssize_t sret;
fn = GNUNET_STRINGS_filename_expand (filename);
LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -333,7 +334,10 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
return GNUNET_SYSERR;
dirty = cfg->dirty; /* back up value! */
if (GNUNET_SYSERR ==
- GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES))
+ GNUNET_DISK_file_size (fn,
+ &fs64,
+ GNUNET_YES,
+ GNUNET_YES))
{
LOG (GNUNET_ERROR_TYPE_WARNING,
"Error while determining the file size of `%s'\n",
@@ -349,7 +353,11 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
}
fs = fs64;
mem = GNUNET_malloc (fs);
- if (fs != GNUNET_DISK_fn_read (fn, mem, fs))
+ sret = GNUNET_DISK_fn_read (fn,
+ mem,
+ fs);
+ if ( (sret < 0) ||
+ (fs != (size_t) sret) )
{
LOG (GNUNET_ERROR_TYPE_WARNING,
_("Error while reading file `%s'\n"),
@@ -495,6 +503,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
char *fn;
char *cfg_buf;
size_t size;
+ ssize_t sret;
fn = GNUNET_STRINGS_filename_expand (filename);
if (fn == NULL)
@@ -505,11 +514,13 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
return GNUNET_SYSERR;
}
cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size);
- if (size != GNUNET_DISK_fn_write (fn, cfg_buf, size,
- GNUNET_DISK_PERM_USER_READ
- | GNUNET_DISK_PERM_USER_WRITE
- | GNUNET_DISK_PERM_GROUP_READ
- | GNUNET_DISK_PERM_GROUP_WRITE))
+ sret = GNUNET_DISK_fn_write (fn, cfg_buf, size,
+ GNUNET_DISK_PERM_USER_READ
+ | GNUNET_DISK_PERM_USER_WRITE
+ | GNUNET_DISK_PERM_GROUP_READ
+ | GNUNET_DISK_PERM_GROUP_WRITE);
+ if ( (sret < 0) ||
+ (size != (size_t) sret) )
{
GNUNET_free (fn);
GNUNET_free (cfg_buf);
@@ -858,13 +869,20 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
*/
void
GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section, const char *option,
+ const char *section,
+ const char *option,
unsigned long long number)
{
char s[64];
- GNUNET_snprintf (s, 64, "%llu", number);
- GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
+ GNUNET_snprintf (s,
+ 64,
+ "%llu",
+ number);
+ GNUNET_CONFIGURATION_set_value_string (cfg,
+ section,
+ option,
+ s);
}
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index aedca232d7..95c05b9d7f 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012 GNUnet e.V.
+ Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2011, 2012, 2018 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
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,
GNUNET_free (bf);
return NULL;
}
- if (fsize == 0)
+ if (0 == fsize)
{
/* found existing empty file, just overwrite */
- if (GNUNET_OK != make_empty_file (bf->fh, size * 4LL))
+ if (GNUNET_OK !=
+ make_empty_file (bf->fh, size * 4LL))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"write");
@@ -525,7 +526,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
return NULL;
}
}
- else if (fsize != size * 4LL)
+ else if (fsize != ((off_t) size) * 4LL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("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,
bf->filename = GNUNET_strdup (filename);
/* Alloc block */
bf->bitArray = GNUNET_malloc_large (size);
- if (bf->bitArray == NULL)
+ if (NULL == bf->bitArray)
{
- if (bf->fh != NULL)
+ if (NULL != bf->fh)
GNUNET_DISK_file_close (bf->fh);
GNUNET_free (bf->filename);
GNUNET_free (bf);
@@ -578,14 +579,18 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size,
/* Read from the file what bits we can */
rbuff = GNUNET_malloc (BUFFSIZE);
pos = 0;
- while (pos < size * 8LL)
+ while (pos < ((off_t) size) * 8LL)
{
int res;
- res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+ res = GNUNET_DISK_file_read (bf->fh,
+ rbuff,
+ BUFFSIZE);
if (res == -1)
{
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "read", bf->filename);
+ LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING,
+ "read",
+ bf->filename);
GNUNET_free (rbuff);
GNUNET_free (bf->filename);
GNUNET_DISK_file_close (bf->fh);
@@ -713,11 +718,11 @@ GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf)
*
* @param e the element
* @param bf the filter
- * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
+ * @return #GNUNET_YES if the element is in the filter, #GNUNET_NO if not
*/
int
-GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
- *bf, const struct GNUNET_HashCode * e)
+GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter *bf,
+ const struct GNUNET_HashCode * e)
{
int res;
@@ -757,7 +762,8 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
*/
int
GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
- const char *data, size_t size)
+ const char *data,
+ size_t size)
{
unsigned int i;
unsigned int n;
@@ -791,8 +797,7 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
*/
int
GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_CONTAINER_BloomFilter
- *to_or)
+ const struct GNUNET_CONTAINER_BloomFilter *to_or)
{
unsigned int i;
unsigned int n;
@@ -828,13 +833,16 @@ GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
*/
void
GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
- const struct GNUNET_HashCode * e)
+ const struct GNUNET_HashCode *e)
{
if (NULL == bf)
return;
- if (bf->filename == NULL)
+ if (NULL == bf->filename)
return;
- iterateBits (bf, &decrementBitCallback, bf, e);
+ iterateBits (bf,
+ &decrementBitCallback,
+ bf,
+ e);
}
/**
@@ -851,7 +859,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
void
GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
GNUNET_CONTAINER_HashCodeIterator iterator,
- void *iterator_cls, size_t size,
+ void *iterator_cls,
+ size_t size,
unsigned int k)
{
struct GNUNET_HashCode hc;
@@ -862,13 +871,16 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
while (i < size)
i *= 2;
size = i; /* make sure it's a power of 2 */
-
+ bf->addressesPerElement = k;
bf->bitArraySize = size;
bf->bitArray = GNUNET_malloc (size);
- if (bf->filename != NULL)
- make_empty_file (bf->fh, bf->bitArraySize * 4LL);
- while (GNUNET_YES == iterator (iterator_cls, &hc))
- GNUNET_CONTAINER_bloomfilter_add (bf, &hc);
+ if (NULL != bf->filename)
+ make_empty_file (bf->fh,
+ bf->bitArraySize * 4LL);
+ while (GNUNET_YES == iterator (iterator_cls,
+ &hc))
+ GNUNET_CONTAINER_bloomfilter_add (bf,
+ &hc);
}
/* end of container_bloomfilter.c */
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 1567c97ce1..3ffacb0a99 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -30,10 +30,17 @@
*/
#define MY_TYPE 256
+#define TIMEOUT GNUNET_TIME_UNIT_SECONDS
+
static int global_ret = 1;
static struct GNUNET_MQ_Handle *mq;
+/**
+ * Timeout task.
+ */
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
handle_recv (void *cls,
@@ -86,10 +93,24 @@ disconnect_cb (void *cls,
{
GNUNET_SCHEDULER_shutdown ();
global_ret = 0;
+ if (NULL != tt)
+ {
+ GNUNET_SCHEDULER_cancel (tt);
+ tt = NULL;
+ }
}
}
+static void
+timeout_task (void *cls)
+{
+ tt = NULL;
+ global_ret = 33;
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Initialization function of the service. Starts
* a client to connect to the service.
@@ -106,7 +127,11 @@ service_init (void *cls,
const char *service_name = cls;
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
-
+
+ GNUNET_assert (NULL == tt);
+ tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &timeout_task,
+ NULL);
mq = GNUNET_CLIENT_connect (cfg,
service_name,
NULL,