This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH, COMMIT: Fix handling of empty input files


Hi Guys,

  I am checking in the patch below to fix a couple of small problems
  that gas can encounter when reading from empty input files.

Cheers
  Nick

PS.  Tristan - would you mind if I applied this patch to the branch ?

gas/ChangeLog
2010-11-17  Nick Clifton  <nickc@redhat.com>

	* input-file.c (input_file_open): Check for empty input files.
	(input_file_get): Check for end of file before reading any more
	data.
	(input_file_give_next_buffer): Likewise.

Index: input-file.c
===================================================================
RCS file: /cvs/src/src/gas/input-file.c,v
retrieving revision 1.27
diff -u -3 -p -r1.27 input-file.c
--- input-file.c	2 Sep 2009 07:24:19 -0000	1.27
+++ input-file.c	17 Nov 2010 11:09:58 -0000
@@ -157,6 +157,15 @@ input_file_open (char *filename, /* "" m
       return;
     }
 
+  /* Check for an empty input file.  */
+  if (feof (f_in))
+    {
+      fclose (f_in);
+      f_in = NULL;
+      return;
+    }
+  gas_assert (c != EOF);
+
   if (c == '#')
     {
       /* Begins with comment, may not want to preprocess.  */
@@ -209,6 +218,9 @@ input_file_get (char *buf, int buflen)
 {
   int size;
 
+  if (feof (f_in))
+    return 0;
+  
   size = fread (buf, sizeof (char), buflen, f_in);
   if (size < 0)
     {
@@ -235,7 +247,13 @@ input_file_give_next_buffer (char *where
   if (preprocess)
     size = do_scrub_chars (input_file_get, where, BUFFER_SIZE);
   else
-    size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
+    {
+      if (feof (f_in))
+	size = 0;
+      else
+	size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
+    }
+
   if (size < 0)
     {
       as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]