Article View: comp.sources.bugs
Article #64Re: Bug in csh (history, "!a%100s"). Report and Fix.
From: Michael Greim
Date: Mon, 10 Jul 1989 11:38
Date: Mon, 10 Jul 1989 11:38
63 lines
3522 bytes
3522 bytes
In article <2218@hp-sdd.hp.com>, allyn@hp-sdd.hp.com (Allyn Fratkin) writes:
> In article <769@sbsvax.UUCP>, greim@sbsvax.UUCP (Michael Greim) writes:
> > This fix works like this:
> > - in error only a string ending in "@" is passed as format string
> > to printf.
> > - only internal error messages needing arguments need format specifiers,
> > so I add a trailing "@" to any such message
> > - any string not ending with "@" is passed to printf with "%s" as first
> > parameter.
>
> nothing personal, but what a disgusting hack. you use @ as the *last*
> character of the string to indicate the presence of a second parameter?
> wouldn't it have been much easier to use the first char?
I never denied that it was a disgusting hack. Most changes in csh will
result in such a thing.
When I decided on how to fix it, I had the following goals in mind:
- The fixes should be to as little files as possible. If people have
done changes to csh, they may have to do the new fixes by hand, and
will be really pissed off, if they have so much to do. (Our csh
contains a lot of changes, e.g. it has a version command, which prints
out csh's version, some special csh variables which change certain
(mis-)behaviours; the format of "time" is changed ...)
- there are a lot more invocations to error with one argument than
there are to error with two arguments.
- No new function unless necessary.
- No new global variables unless necessary.
- Didn't want to spend too much time on it.
- I did not use "@" as the first character, because the command
!@%10s would then still produce 10 spaces, as error would see "@%10s",
think: "aha, it starts with @, so it is a format string", call
printf ("%10s", ... which will produce 10 space, and maybe a core
dump.
I decided on "@" because no valid error message from inside csh
can end with a "@".
>
> but why didn't you just change the calls
> error(singlearg);
> to
> error("%s", singlearg);
>
> seems like it would have been much cleaner.
Maybe, but there are several error function, which package the messages
in several ways. If one uses "error(fmt, arg)", one must replace some
calls to seterr2 and seterrc, one must trace possible calls to "error(av)"
"Perror" or to "error" of the form "error(err)" to see,
where the "av" really comes from, and probably change some other calls too,
if the "av" can contain a "%".
I preferred the simple, though ugly way, as I did not want to spend a lot of
time on the investigation whether any alternative might yield a more
beautiful fix.
> From the virtual mind of Allyn Fratkin allyn@sdd.hp.com
> San Diego Division - or -
> Hewlett-Packard Company uunet!ucsd!hp-sdd!allyn
-mg
--
Michael Greim Email : greim@sbsvax.informatik.uni-saarland.dbp.de
or : ...!uunet!unido!sbsvax!greim
[.signature removed by the board of censors for electronic mail's main
executive computer because it contained a four letter word ("word")]
Technical Details
Message-ID:
<773@sbsvax.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!uunet!mcvax!unido!sbsvax!greimReferences:
<769@sbsvax.UUCP> <2218@hp-sdd.hp.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!uunet!mcvax!unido!sbsvax!greim From: greim@sbsvax.UUCP (Michael Greim) Newsgroups: comp.sources.bugs Subject: Re: Bug in csh (history, "!a%100s"). Report and Fix. Message-ID: <773@sbsvax.UUCP> Date: 10 Jul 89 11:38:56 GMT References: <769@sbsvax.UUCP> <2218@hp-sdd.hp.com> Organization: Universitaet des Saarlandes, Saarbruecken, W-Germany Lines: 63