[comp.os.minix] Estdio 2.1: bugs in scanf %[] handling, plus fix

jds@cs.umd.edu (James da Silva) (04/01/91)

There are two problems with Estdio's handling of %[] "scanset" formats
in scanf.

1. Estdio scanf stops the scan on whitespace.  This is not consistent
with the various Unix scanf() implementations I've seen.  I'm not sure
what ANSI says, but I *presume* it doesn't mandate Estdio's behavior;
that would break a lot of code (including some I've just been foisted
with :-).

2. The test for set membership is wrong.  The bittest() macro returns
the actual masked word if the bit is set, rather than just 0 or 1, so
the bitwise xor with a boolean flag doesn't work.  Simple rearrangement
of the expression is all that is needed.

Both problems are solved by changing one line:

*** /tmp/RCSA000345	Mon Apr  1 01:36:56 1991
--- _vfscanf.c	Mon Apr  1 01:33:19 1991
***************
*** 320,326 ****
  
  /* Scan input for satisfactory characters */
        while (fieldwidth < 0 || fieldwidth--) {
!         if (BLANK(ch) || ch <= 0 || ! (bittest(cset, ch) ^ invertedset))
  	  break;
  	if (! noassign)
  	  *p++ = ch;
--- 320,326 ----
  
  /* Scan input for satisfactory characters */
        while (fieldwidth < 0 || fieldwidth--) {
!         if (ch <= 0 || !bittest(cset, ch) ^ invertedset)
  	  break;
  	if (! noassign)
  	  *p++ = ch;


Jaime
...........................................................................
: domain: jds@cs.umd.edu				     James da Silva
: path:   uunet!mimsy!jds		    Systems Design & Analysis Group