Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!gatech!hao!oddjob!gargoyle!ihnp4!cbosgd!cwruecmp!hal!ncoast!allbery
From: allbery@ncoast.UUCP (Brandon Allbery)
Newsgroups: comp.bugs.misc,comp.bugs.4bsd
Subject: Re: doscan.o bug in Ultrix 1.2 & 2.0
Message-ID: <2852@ncoast.UUCP>
Date: Fri, 10-Jul-87 23:53:16 EDT
Article-I.D.: ncoast.2852
Posted: Fri Jul 10 23:53:16 1987
Date-Received: Sun, 12-Jul-87 15:55:32 EDT
References: <309@nsta.UUCP>
Reply-To: allbery@ncoast.UUCP (Brandon Allbery)
Followup-To: comp.bugs.misc
Distribution: world
Organization: Cleveland Public Access UN*X, Cleveland, Oh
Lines: 31
Xref: mnetor comp.bugs.misc:59 comp.bugs.4bsd:436
As quoted from <309@nsta.UUCP> by tom@nsta.UUCP (Tom Gorodecki):
+---------------
| Bug in doscan.o in /lib/libc.a on ULTRIX 1.2 and ULTRIX 2.0.
| Try in you program.c the following line:
|
| val = fscanf(file,"%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyz
| ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]", namebuf);
|
| In case your input does not begin with space, tab or newline, scanf will
| return 0 which is not right, since "*" should match "0 or more" .
+---------------
* means match but don't assign. As to whether %[ succeeds on match 0 instances,
this appears to be a matter of interpretation; there isn't an answer. (I
discovered this when UC 0.4.3 used %[ in userfile parsing; I recoded the
getuser() routine to avoid it for 0.4.4.)
In general, it's best not to use fscanf() unless you are absolutely certain
of the file's format. (News B2.11 is quite fragile in this regard.) I
would solve it (for anything but Pascal I/O )-: by fgets(), then skip over
leading whitespace and sscanf() the string. For Pascal, it gets harder;
the "best" way is skip whitespace, then read characters until you match the
longest value-string defined for the scalar type being input. (If the list
is organized in alphabetical order (or an array of pointers to them is so
organized), this can be done optimally.
--
[Copyright 1987 Brandon S. Allbery, all rights reserved] \ ncoast 216 781 6201
[Redistributable only if redistribution is subsequently permitted.] \ 2400 bd.
Brandon S. Allbery, moderator of comp.sources.misc and comp.binaries.ibm.pc
{{ames,harvard,mit-eddie}!necntc,{well,ihnp4}!hoptoad,cbosgd}!ncoast!allbery
<>