[comp.sources.d] Bug in cshar

vic@cucumber.Princeton.EDU (Victor Duchovni) (10/23/88)

--
	I can not get mail through to <rsaltz@uunet.uu.net> (Are you there??)
So here goes.  The cshar program posted by R. Saltz bombs on files whose
last line is not '\n' terminated.  The resulting archives are unuseable.

	Here is the fix  (Make sure to add -DNEW_LINE_FIX to CFLAGS in
	the Makefile).

To: rsaltz@uunet.UU.NET
Subject: Bug report (and fix) for "shar.c".
Date: Sat, 22 Oct 88 17:03:42 EDT
From: Victor Duchovni <vic@fine.princeton.edu>

   The shar package at patchlevel 3, incorrectly handles ASCII files
with missing newline before EOF (as frequently generated by emacs).

   The current behaviour generates no warnings and appends the 
"END_OF_FILE" to the last line, corrupting the archive.

   The fix is to test the last char of the file against '\n'
Issue warnings,  and add the '\n' if missing.  The patch is below.

*** /tmp/,RCSt1a00333	Mon Oct 17 14:46:10 1988
--- shar.c	Mon Oct 17 14:43:43 1988
***************
*** 91,98 ****
  		}
  	    }
  
! 	/* Tell about and control characters. */
  	Printf("END_OF_FILE\n", Name);
  	if (Bads) {
  	    Printf(
      "echo shar: %d control character%s may be missing from \\\"'%s'\\\"\n",
--- 91,113 ----
  		}
  	    }
  
! #ifdef NEW_LINE_FIX
! 
! 	    if ( *--s != '\n' )  /* No terminating new line */
! 	        (void)putchar('\n') ;
! 
!             Printf("END_OF_FILE\n",Name);
! 
! 	    if ( *s != '\n' )  { /* No terminating new line */
! 		Fprintf(stderr,"Warning: trailing <nl> added to %s\n",Name) ;
! 		Printf(
! 	"echo shar: Warning \\<nl\\> added at end of %s\n",Name) ;
! 		++Size ;
!             }
! #else
  	Printf("END_OF_FILE\n", Name);
+ #endif
+ 	/* Tell about and control characters. */
  	if (Bads) {
  	    Printf(
      "echo shar: %d control character%s may be missing from \\\"'%s'\\\"\n",

--
	Victor Duchovni <vic@fine.princeton.edu>