From 0a2aed43c74effdc10e17c50d4070afd71894ca3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Thu, 7 Jul 2011 22:42:55 +0200
Subject: [PATCH] (read_file): Bug fix, in dependence on initial size on
 max_size.

Rev: nettle/examples/io.c:1.4
---
 examples/io.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/examples/io.c b/examples/io.c
index 689e0f60..c24546f5 100644
--- a/examples/io.c
+++ b/examples/io.c
@@ -88,8 +88,13 @@ read_file(const char *name, unsigned max_size, char **contents)
     size = max_size;
   else
     size = 100;
-  
-  for (size = 100, done = 0;
+
+  /* FIXME: The use of feof and ferror in this loop is a bit confused
+     (but I think it is still correct). We should check the return
+     value of fread, and call feof and/or ferror when we get a short
+     item count. */	
+
+  for (done = 0;
        (!max_size || done < max_size) && !feof(f);
        size *= 2)
     {
-- 
GitLab