From xemacs-m  Sun Aug 24 00:42:40 1997
Received: from GS213.SP.CS.CMU.EDU (GS213.SP.CS.CMU.EDU [128.2.209.183])
	by xemacs.org (8.8.5/8.8.5) with SMTP id AAA04306
	for <xemacs-beta@xemacs.org>; Sun, 24 Aug 1997 00:42:40 -0500 (CDT)
Received: by GS213.SP.CS.CMU.EDU (AIX 3.2/UCB 5.64/4.03)
          id AA13027; Sun, 24 Aug 1997 01:42:37 -0400
Date: Sun, 24 Aug 1997 01:42:37 -0400
Message-Id: <9708240542.AA13027@GS213.SP.CS.CMU.EDU>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
From: Darrell Kindred <dkindred@cmu.edu>
To: xemacs-beta@xemacs.org
Subject: [PATCH] 19.16b90: fileio error msgs
Organization: Carnegie Mellon University School of Computer Science
X-Mailer: VM 6.22 under 19.15 XEmacs Lucid

A Digital Unix 3.2 user here recently got a core dump from
19.15, which appeared to result from a bad errno received
in fileio.c.  The strange errno led strerror() to return
NULL, which leads to trouble.

The patch below modifies emacs_doprnt_1() to do something
reasonable (print "(null)") when it gets a null %s argument.
It also adds a check in fileio.c in another spot where
a failed strerror() could cause trouble.  A more thorough
solution would be to check the return value of strerror()
everywhere, but I think it's better not to make that big a
change at this stage.

This patch will fit 19.16b90.

- Darrell

*** /afs/cs/misc/xemacs/src/xemacs-19.15/src/doprnt.c.orig	Sun Feb  2 00:07:07 1997
--- /afs/cs/misc/xemacs/src/xemacs-19.15/src/doprnt.c	Thu Aug 14 14:49:14 1997
***************
*** 445,450 ****
--- 445,459 ----
  	  if (!largs)
  	    {
  	      string = Dynarr_at (args, spec->argnum - 1).bp;
+ 	      /* error() can be called with null string arguments.
+ 		 E.g., in fileio.c, the return value of strerror()
+ 		 is never checked.  We'll print (null), like some
+ 		 printf implementations do.  Would it be better (and safe)
+ 		 to signal an error instead?  Or should we just use the 
+                  empty string?  -dkindred@cs.cmu.edu 8/1997
+ 	       */
+ 	      if (!string)
+ 		string = "(null)";
  	      string_len = strlen ((char *) string);
  	    }
  	  else
*** /afs/cs/misc/xemacs/src/xemacs-19.15/src/fileio.c.orig	Wed Mar 26 13:23:37 1997
--- /afs/cs/misc/xemacs/src/xemacs-19.15/src/fileio.c	Thu Aug 14 14:55:06 1997
***************
*** 123,129 ****
  
    /* System error messages are capitalized.  Downcase the initial
       unless it is followed by a slash.  */
!   if (string_char (XSTRING (errstring), 1) != '/')
      set_string_char (XSTRING (errstring), 0,
  		     DOWNCASE (current_buffer,
  			       string_char (XSTRING (errstring), 0)));
--- 123,130 ----
  
    /* System error messages are capitalized.  Downcase the initial
       unless it is followed by a slash.  */
!   if (string_char_length (XSTRING (errstring)) >= 2
!       && string_char (XSTRING (errstring), 1) != '/')
      set_string_char (XSTRING (errstring), 0,
  		     DOWNCASE (current_buffer,
  			       string_char (XSTRING (errstring), 0)));

