From 3e697f238da8de2bc490d33da0660afc1dd14fbf Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 5 Nov 2009 13:50:25 +0000 Subject: [PATCH] fixes --- src/util/bio.c | 8 +++++++- src/util/test_bio.c | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/bio.c b/src/util/bio.c index 860e9e63e..1143e89de 100644 --- a/src/util/bio.c +++ b/src/util/bio.c @@ -58,6 +58,8 @@ GNUNET_BIO_read_open (const char *fn) fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); + if (NULL == fd) + return NULL; h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); h->buffer = (char *) &h[1]; h->size = BIO_BUFFER_SIZE; @@ -176,15 +178,16 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, return GNUNET_SYSERR; } buf = GNUNET_malloc (big); + *result = buf; buf[--big] = '\0'; if (big == 0) return GNUNET_OK; if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) { GNUNET_free (buf); + *result = NULL; return GNUNET_SYSERR; } - *result = buf; return GNUNET_OK; } @@ -308,6 +311,8 @@ GNUNET_BIO_write_open (const char *fn) GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + if (NULL == fd) + return NULL; h = GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); h->buffer = (char *) &h[1]; @@ -390,6 +395,7 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, h->have = 0; } while (pos < n); /* should always be true */ + GNUNET_break (0); return GNUNET_OK; } diff --git a/src/util/test_bio.c b/src/util/test_bio.c index d2eb4ae21..fbcfa02ac 100644 --- a/src/util/test_bio.c +++ b/src/util/test_bio.c @@ -123,9 +123,11 @@ main (int argc, char *argv[]) GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum)); fileR2 = GNUNET_BIO_read_open (fileName2); GNUNET_assert (NULL != fileR2); + readResultString = (char*) "not null"; GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (fileR2, "Read string error", &readResultString, 200)); + GNUNET_assert (NULL == readResultString); fileR3 = GNUNET_BIO_read_open (fileName3); GNUNET_assert (NULL != fileR3); GNUNET_assert (GNUNET_SYSERR == -- 2.25.1