|  | diff -ur bash-4.3.30.dist/builtins/echo.def bash-4.3.30/builtins/echo.def | 
|  | --- bash-4.3.30.dist/builtins/echo.def	2011-06-29 09:55:58.000000000 -0400 | 
|  | +++ bash-4.3.30/builtins/echo.def	2016-06-03 17:40:57.834915855 -0400 | 
|  | @@ -108,8 +108,10 @@ | 
|  | echo_builtin (list) | 
|  | WORD_LIST *list; | 
|  | { | 
|  | -  int display_return, do_v9, i, len; | 
|  | -  char *temp, *s; | 
|  | +  int display_return, do_v9, i, j, len, malloc_len; | 
|  | +  char *temp, *s, *m; | 
|  | +  WORD_LIST *save_list; | 
|  | +  ssize_t ret; | 
|  |  | 
|  | do_v9 = xpg_echo; | 
|  | display_return = 1; | 
|  | @@ -162,6 +164,30 @@ | 
|  | clearerr (stdout);	/* clear error before writing and testing success */ | 
|  |  | 
|  | terminate_immediately++; | 
|  | +  malloc_len = 0; | 
|  | +  m = NULL; | 
|  | +  save_list = list; | 
|  | +  while (list) | 
|  | +    { | 
|  | +      i = len = 0; | 
|  | +      temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), 1, &i, &len) | 
|  | +		   : list->word->word; | 
|  | +      if (!temp) | 
|  | +        continue; | 
|  | +      malloc_len += do_v9 ? len : strlen(temp); | 
|  | +      if (do_v9) | 
|  | +	free (temp); | 
|  | +      list = list->next; | 
|  | +      if (list) | 
|  | +        malloc_len++; | 
|  | +    } | 
|  | +  if (display_return) | 
|  | +    malloc_len++; | 
|  | +  m = malloc(malloc_len); | 
|  | +  if (m == NULL) | 
|  | +    fatal_error ("echo: could not allocate %lu bytes", (unsigned long)malloc_len); | 
|  | +  list = save_list; | 
|  | +  j = 0; | 
|  | while (list) | 
|  | { | 
|  | i = len = 0; | 
|  | @@ -169,19 +195,13 @@ | 
|  | : list->word->word; | 
|  | if (temp) | 
|  | { | 
|  | -	  if (do_v9) | 
|  | -	    { | 
|  | -	      for (s = temp; len > 0; len--) | 
|  | -		putchar (*s++); | 
|  | -	    } | 
|  | -	  else | 
|  | -	    printf ("%s", temp); | 
|  | -#if defined (SunOS5) | 
|  | -	  fflush (stdout);	/* Fix for bug in SunOS 5.5 printf(3) */ | 
|  | -#endif | 
|  | +	  if (!do_v9) | 
|  | +              len = strlen(temp); | 
|  | +          memmove(m + j, temp, len); | 
|  | +          j += len; | 
|  | +          if (do_v9) | 
|  | +            free (temp); | 
|  | } | 
|  | -      if (do_v9 && temp) | 
|  | -	free (temp); | 
|  | list = list->next; | 
|  | if (i) | 
|  | { | 
|  | @@ -189,11 +209,17 @@ | 
|  | break; | 
|  | } | 
|  | if (list) | 
|  | -	putchar(' '); | 
|  | +	m[j++] = ' '; | 
|  | } | 
|  | - | 
|  | if (display_return) | 
|  | -    putchar ('\n'); | 
|  | +    m[j++] = '\n'; | 
|  | +  ret = write(STDOUT_FILENO, m, j); | 
|  | +  if (ret < j) | 
|  | +    sh_wrerror(); | 
|  | +  free(m); | 
|  | +#if defined (SunOS5) | 
|  | +  fflush (stdout);	/* Fix for bug in SunOS 5.5 printf(3) */ | 
|  | +#endif | 
|  |  | 
|  | terminate_immediately--; | 
|  | return (sh_chkwrite (EXECUTION_SUCCESS)); |