[5125] in Athena Bugs

home help back first fref pref prev next nref lref last post

stdio: ungetc

daemon@ATHENA.MIT.EDU (John Carr)
Fri Jun 8 15:19:21 1990

To: bugs@ATHENA.MIT.EDU
Date: Fri, 08 Jun 90 15:19:06 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>


ungetc should check to see if the stream it is being called on is a
string, and not store back the character to the buffer in that case
(since the character that is there is the right one).  An equivalent
patch is this one, which doesn't store back the character if the store
would have no effect.  This is needed to prevent ungetc from dumping
core when called on a stream that is really a constant (read-only)
string.

*** /source/bsd-4.3/common/lib/libc/stdio/ungetc.c	Wed Mar 26 21:08:43 1986
--- ungetc.c	Thu Jun  7 10:14:23 1990
***************
*** 18,24 ****
  			return (EOF);
  
  	iop->_cnt++;
! 	*--iop->_ptr = c;
  
  	return (c);
  }
--- 18,25 ----
  			return (EOF);
  
  	iop->_cnt++;
! 	if(*--iop->_ptr != c)
! 	  *iop->_ptr = c;
  
  	return (c);
  }


home help back first fref pref prev next nref lref last post