diff mbox

Fix precompiled header for '-' being input file (PR, pch/78970)

Message ID 2577a04a-611e-ab46-b2c5-f39c71f02cca@suse.cz
State New
Headers show

Commit Message

Martin Liška Jan. 5, 2017, 9 a.m. UTC
Having '-' used as indication that input should be taken from standard input
is unfriendly to pch which calculates md5sum of all input file descriptors.
With that fdopen fails for STDIN_FILENO. To be honest my patch is just a workaround
for the ICE. Is there a better solution for that?

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

Comments

Jakub Jelinek Jan. 5, 2017, 9:11 a.m. UTC | #1
On Thu, Jan 05, 2017 at 10:00:33AM +0100, Martin Liška wrote:
> Having '-' used as indication that input should be taken from standard input

> is unfriendly to pch which calculates md5sum of all input file descriptors.

> With that fdopen fails for STDIN_FILENO. To be honest my patch is just a workaround

> for the ICE. Is there a better solution for that?


Shouldn't we just error on trying to create PCH for - ?
I mean, how are you going to use such a PCH file?  ./- is something
different from - .

If it makes some sense (I don't see it), then the question is if the stdin
is seakable or not.  If it is not seakable, don't we reject it already, or
aren't there other places where we want to seek on it?
If it is seakable, then you might e.g. just read it into a buffer in a loop
and md5sum the buffer instead of md5summing the stream.

	Jakub
diff mbox

Patch

From ad7f98ed0412e5213f5be9894bcf021b6bf93450 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 4 Jan 2017 16:04:44 +0100
Subject: [PATCH] Fix precompiled header for '-' being input file (PR
 pch/78970)

libcpp/ChangeLog:

2017-01-04  Martin Liska  <mliska@suse.cz>

	PR pch/78970
	* files.c (_cpp_save_file_entries): Do not calculate md5sum
	when input file is STDIN.
---
 libcpp/files.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libcpp/files.c b/libcpp/files.c
index 969a531033f..cc597d4f22a 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -1885,9 +1885,13 @@  _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
 	      free (result);
 	      return false;
 	    }
-	  ff = fdopen (f->fd, "rb");
-	  md5_stream (ff, result->entries[count].sum);
-	  fclose (ff);
+	  /* Skip STDIN as fdopen would fail for the file descriptor.  */
+	  if (f->fd != STDIN_FILENO)
+	    {
+	      ff = fdopen (f->fd, "rb");
+	      md5_stream (ff, result->entries[count].sum);
+	      fclose (ff);
+	    }
 	  f->fd = oldfd;
 	}
       result->entries[count].size = f->st.st_size;
-- 
2.11.0