[comp.lang.c] readonly strings vs. sscanf

chris@mimsy.UUCP (Chris Torek) (01/06/88)

In article <633@mcdsun.UUCP> fnf@mcdsun.UUCP (Fred Fish) writes:
>I have a feeling [readonly strings are] going to break more code than
>just the obvious stuff, including something deep in the bowels of stdio.

[example of sscanf using ungetc to put back a character in a non-file
`stream' causing segmentation fault deleted]

This is easy to fix.  The changes I made to 4.3BSD stdio to allow
functions as streams also included something that happens to fix
this as well as a nastier bug (one that might quiety corrupt a byte
somewhere) involving unbuffered streams and low free memory.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

daveb@geac.UUCP (David Collier-Brown) (01/07/88)

>In article <633@mcdsun.UUCP> fnf@mcdsun.UUCP (Fred Fish) writes:
>>I have a feeling [readonly strings are] going to break more code than
>>just the obvious stuff, including something deep in the bowels of stdio.
>>...

In article <10051@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>This is easy to fix.  The changes I made to 4.3BSD stdio to allow
>functions as streams also included something that happens to fix
>this as well as a nastier bug (one that might quietly corrupt a byte
>somewhere) involving unbuffered streams and low free memory.

  The old read/write strings were required in order to simulate
statics back before they were put in the compiler. In

bar() {
	char	*foo = "fred";
	...

  foo was auto, but "fred" was effectively static.  This was then used
in a few (hopefully VERY few) programs to simulate having a static
flag variable: you stored data-to-be-kept to *foo or foo[n].
  I strongly suspect that the programs which depended on that are
rare, elderly and obsolete.  Ie, they were fixed in v7.  That they
weren't fixed in BSD until 4.3 reflects rather badly on someone, and
rather well on Chris for spotting and deleting them.

 --dave (put 'em in the code space! thats where they belong in D) c-b
-- 
 David Collier-Brown.                 {mnetor|yetti|utgpu}!geac!daveb
 Geac Computers International Inc.,   |  Computer Science loses its
 350 Steelcase Road,Markham, Ontario, |  memory (if not its mind)
 CANADA, L3R 1B3 (416) 475-0525 x3279 |  every 6 months.