Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tekcrl.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!dual!qantel!hplabs!tektronix!tekcrl!terryl From: terryl@tekcrl.UUCP Newsgroups: net.unix-wizards Subject: Major do-do in ungetc (stdio /usr/src/libc/stdio/ungetc.c) Message-ID: <224@tekcrl.UUCP> Date: Sun, 11-Aug-85 04:01:54 EDT Article-I.D.: tekcrl.224 Posted: Sun Aug 11 04:01:54 1985 Date-Received: Wed, 14-Aug-85 22:26:58 EDT Lines: 33 I'm working on a software project that uses shared memory to pass messages around to co-operating processes. The messages are composed with sprintf(), and are de-composed with sscanf. Once the messages are composed and sent to the co-operating processes, the messages are made READ-ONLY. Now this has shown up when trying to de-compose the message with sscanf. sscanf creates a funny FILE pointer with the base address as the address string as the base of the buffer, and the length of the string as the length. sscanf also set a flag that this funny FILE pointer has an _IOSTRG attribute. Well, sscanf then calls _doscan to do the actual work, and _doscan, when parsing the string according to the format field (the % whatevers) keeps doing getc's until it finds the end of current field according to the current the format field, and when it finds the end, it has scanned one character pass the end of the current field and so does an ungetc because it has read one too many characters of the input stream(the string). ungetc actually puts the character back into the input stream according to the current FILE pointer, and this is where the problem is. Below is the fragment of ungetc that causes the problem: if ((iop->_flag&_IOREAD) == 0 || iop->_ptr <= iop->_base) if (iop->_ptr == iop->_base && iop->_cnt == 0) *iop->_ptr++; else return (EOF); iop->_cnt++; *--iop->_ptr = c; /* This is the problem */ return (c); } Now my question is this: since only sscanf is the one who uses the _IOSTRG construct, is it safe to make the assignment marked /* This is the problem */ into just a decrement of the pointer into a string????