From 89a92869e56aba4e4cab2d639c00a86f0545c862 Mon Sep 17 00:00:00 2001
From: Chet Ramey <chet.ramey@case.edu>
Date: Mon, 21 Nov 2011 20:49:12 -0500
Subject: Bash-4.0 patchlevel 38

---
 builtins/read.def | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

(limited to 'builtins/read.def')

diff --git a/builtins/read.def b/builtins/read.def
index fb4366f..8fc5647 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -369,14 +369,14 @@ read_builtin (list)
       code = setjmp (alrmbuf);
       if (code)
 	{
-#if 0
+	  /* Tricky.  The top of the unwind-protect stack is the free of
+	     input_string.  We want to run all the rest and use input_string,
+	     so we have to remove it from the stack. */
+	  remove_unwind_protect ();
 	  run_unwind_frame ("read_builtin");
-	  return (EXECUTION_FAILURE);
-#else
 	  input_string[i] = '\0';	/* make sure it's terminated */
-	  retval = 128+SIGALRM;;
+	  retval = 128+SIGALRM;
 	  goto assign_vars;
-#endif
 	}
       old_alrm = set_signal_handler (SIGALRM, sigalrm);
       add_unwind_protect (reset_alarm, (char *)NULL);
@@ -601,14 +601,15 @@ add_char:
   if (unbuffered_read == 0)
     zsyncfd (fd);
 
-  interrupt_immediately--;
-  terminate_immediately--;
   discard_unwind_frame ("read_builtin");
 
   retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
 
 assign_vars:
 
+  interrupt_immediately--;
+  terminate_immediately--;
+
 #if defined (ARRAY_VARS)
   /* If -a was given, take the string read, break it into a list of words,
      an assign them to `arrayname' in turn. */
@@ -763,7 +764,10 @@ assign_vars:
       if (*input_string == 0)
 	tofree = input_string = t;
       else
-	input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+	{
+	  input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);
+	  tofree = t;
+	}
     }
 #endif
 
-- 
cgit v1.2.3

