fixes
authorChristian Grothoff <christian@grothoff.org>
Thu, 5 Nov 2009 13:50:25 +0000 (13:50 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 5 Nov 2009 13:50:25 +0000 (13:50 +0000)
src/util/bio.c
src/util/test_bio.c

index 860e9e63eb63e8a93d74106df0cfe5f1733b2064..1143e89de82c70577cdb8065ba5ec7e515fe1bd8 100644 (file)
@@ -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;
 }
 
index d2eb4ae21cd38d6245b0048df5180eebde1ecedd..fbcfa02ac0d2bba6f38b0c02e36c3ec55d423a16 100644 (file)
@@ -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 ==