🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #925

Re: bug in sscanf (scanf)?

#925
From: John Woods
Date: Fri, 18 Nov 1988 05:04
19 lines
1277 bytes
In article <331@zeus.hf.intel.com>, martin@zeus.hf.intel.com (Martin Wilde) writes:
> I have a small fragment of code that does not work on V.3.2 386 UNIX. 
> The problem appears to be in sscanf (scanf).   The following fragment of
> code shows the problem.
> 
> 
>(void) sscanf(optarg, "%d %s %s %s %255[^\0]", &times, s1, s2, s3, s4);

The problem is here.......................^^

That puts a NUL byte into the format string, which terminates it; as far as
C semantics are concerned, scanf should assume that nothing follows it.
XENIX evidently blithely went on, but System V definitely stops (and ignores
the format specification) if it sees a premature NUL byte.
-- 
John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101
...!decvax!frog!john, john@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu

Science does not remove the TERROR of the Gods!
Technical Details
Message-ID: <1278@X.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!bellcore!texbell!killer!ames!nrl-cmf!ukma!gatech!purdue!bu-cs!mirror!frog!john
References: <331@zeus.hf.intel.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!clyde!bellcore!texbell!killer!ames!nrl-cmf!ukma!gatech!purdue!bu-cs!mirror!frog!john
From: john@frog.UUCP (John Woods)
Newsgroups: comp.bugs.sys5
Subject: Re: bug in sscanf (scanf)?
Keywords: SVID problem?
Message-ID: <1278@X.UUCP>
Date: 18 Nov 88 05:04:00 GMT
References: <331@zeus.hf.intel.com>
Organization: Servants of the Great White Frog
Lines: 19