From 767d8811bff86a63cde07f73a6f8b47dae14672b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Fran=C3=A7ois=20Pinard?= <pinard@iro.umontreal.ca>
Date: Mon, 18 Feb 2008 19:52:21 -0500
Subject: [PATCH] Get error_at_step initialized when errors

---
 src/ChangeLog |  7 +++++++
 src/task.c    | 10 ++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 4f237f9..1830617 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -23,6 +23,13 @@
 	* Makefile.am: Replace lib_LTLIBRARIES by noinst_LIBRARIES.
 	Replace librecode.la by libcode.a and librecode_la by librecode_a.
 
+2001-07-01  Bruno Haible  <haible@clisp.cons.org>
+
+	* task.c (perform_pass_sequence): Call recode_if_nogo before
+	returning false.  Otherwise task->error_at_step is not set, and
+	main() dumps core.
+	Reported by David Necas, Konstantin Osipov and Stephen Grecni.
+
 2001-01-22  Bruno Haible  <haible@clisp.cons.org>
 
 	* hash.c: Avoid use of undefined macros HAVE_DECL_MALLOC/FREE.
diff --git a/src/task.c b/src/task.c
index 7ccee89..d23d4fb 100644
--- a/src/task.c
+++ b/src/task.c
@@ -485,6 +485,9 @@ perform_pass_sequence (RECODE_TASK task)
 	 && task->error_so_far < task->abort_level;
        sequence_index++)
     {
+      step = request->sequence_array + sequence_index;
+      subtask->step = step;
+
       /* Select the input text for this step.  */
 
       if (sequence_index == 0)
@@ -499,6 +502,7 @@ perform_pass_sequence (RECODE_TASK task)
 		       subtask->input.file == NULL)
 		{
 		  recode_perror (NULL, "fopen (%s)", subtask->input.name);
+		  recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
 		  return false;
 		}
 	    }
@@ -510,6 +514,7 @@ perform_pass_sequence (RECODE_TASK task)
 	      subtask->input.file == NULL)
 	    {
 	      recode_perror (outer, "fopen (%s)", input.name);
+	      recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
 	      return false;
 	    }
 #endif
@@ -535,6 +540,7 @@ perform_pass_sequence (RECODE_TASK task)
 	      subtask->output.file == NULL)
 	    {
 	      recode_perror (outer, "fopen (%s)", subtask->output.name);
+	      recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
 	      return false;
 	    }
 #endif
@@ -543,6 +549,7 @@ perform_pass_sequence (RECODE_TASK task)
 	  if (subtask->output.file = tmpfile (), subtask->output.file == NULL)
 	    {
 	      recode_perror (NULL, "tmpfile ()");
+	      recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
 	      return false;
 	    }
 #endif
@@ -560,6 +567,7 @@ perform_pass_sequence (RECODE_TASK task)
 		       subtask->output.file == NULL)
 		{
 		  recode_perror (NULL, "fopen (%s)", subtask->output.name);
+		  recode_if_nogo (RECODE_SYSTEM_ERROR, subtask);
 		  return false;
 		}
 	    }
@@ -567,8 +575,6 @@ perform_pass_sequence (RECODE_TASK task)
 
       /* Execute one recoding step.  */
 
-      step = request->sequence_array + sequence_index;
-      subtask->step = step;
       (*step->transform_routine) (subtask);
 
       /* Post-step clean up.  */
-- 
2.40.0