diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-01-04 16:46:18 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-01-04 16:46:18 +0100 |
commit | e20eca334a33b8340524a8fa6ad1d6b606e1dd0c (patch) | |
tree | e79ce20f787cae4aea7403d2e9c9b8fb2546ad1f /src/util/bio.c | |
parent | 056ca89d207cd1865a90fe3fcd430a4381097da5 (diff) | |
download | gnunet-e20eca334a33b8340524a8fa6ad1d6b606e1dd0c.tar.gz gnunet-e20eca334a33b8340524a8fa6ad1d6b606e1dd0c.zip |
fix timeout of test_service, misc signed/unsigned and unused argument issues
Diffstat (limited to 'src/util/bio.c')
-rw-r--r-- | src/util/bio.c | 69 |
1 files changed, 51 insertions, 18 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) |