[net.sources.bugs] Fix for a malloc problem in patch

geoff@desint.UUCP (Geoff Kuenning) (11/27/84)

In article <320@rna.UUCP> dan@rna.UUCP (Dan Ts'o) writes:

>	Alas things are still not well with patch - I occassionally get
>core dumps in malloc(), via savestr(), but I haven't had a chance to
>track that one down yet. It seems to happen when patch can't find the
>appropriate file, but it may be something else. Sigh... A valiant
>program, tho...

I have found a malloc bug in patch that made it completely unworkable on
my system.  Hand-made context diff's follow;  please no flames if they fail
to pass through 'patch'.

*** patch.c.orig	Nov 25 01:56
--- patch.c	Nov 26 13:02
***************
*** 753,759
  	if (*s == '\n')
  	    iline++;
      }
!     i_ptr = (char **)malloc((iline + 1) * sizeof(char *));
      if (i_ptr == Null(char **)) {	/* shucks, it was a near thing */
  	free(i_womp);
  	return FALSE;
--- 753,759 -----
  	if (*s == '\n')
  	    iline++;
      }
!     i_ptr = (char **)malloc((iline + 2) * sizeof(char *));
      if (i_ptr == Null(char **)) {	/* shucks, it was a near thing */
  	free(i_womp);
  	return FALSE;
-- 

	Geoff Kuenning
	...!ihnp4!trwrb!desint!geoff