bug-m4
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for m4-1.4.1


From: Marion Hakanson
Subject: patch for m4-1.4.1
Date: Mon, 19 Jul 2004 11:33:05 -0700

Folks,

The following fixes a mysterious (to me, anyway :-) early-abort problem
with m4-1.4.1 on SPARC/Solaris (Solaris-9 here, but probably other versions
as well).  The symptom of the problem is an early exit of m4 with a message
reading something like:

  configure.ac:69: /usr/local/bin/gm4: ERROR: Reading inserted file: No such 
file or directory

Actually, the bug should affect any system which does not guarantee
that "errno" is preserved across calls to various C-library routines,
which I believe could affect many different Unix-like systems.

In this particular case, a trace of the running m4-1.4.1 binary on
this platform appears to show that the C library routine "tmpfile()" uses 
stat() to check for the existence of a candidate temp-file name before it
then creates/opens the temporary file.  This is happening as a result of
the patched function insert_file() in src/output.c calling output_text(),
which in turn can call make_room_for(), which calls tmpfile().

The problem goes away after applying this patch:

===============
--- src/output.c.orig   Fri Jul 16 16:21:23 2004
+++ src/output.c        Fri Jul 16 16:23:35 2004
@@ -459,6 +459,7 @@
 {
   char buffer[COPY_BUFFER_SIZE];
   size_t length;
+  int saved_errno;
 
   /* Optimize out inserting into a sink.  */
 
@@ -469,8 +470,11 @@
 
   errno = 0;
   while (length = fread (buffer, 1, COPY_BUFFER_SIZE, file),
-        length != 0)
+        length != 0) {
+    saved_errno = errno;
     output_text (buffer, length);
+    errno = saved_errno;
+  }
   if (errno)
     M4ERROR ((EXIT_FAILURE, errno, "ERROR: Reading inserted file"));
 }
===============

I have not made a search of m4's code for other instances of this type
of problem, so it could be that other such assumptions are present.

Regards,

-- 
Marion Hakanson







reply via email to

[Prev in Thread] Current Thread [Next in Thread]