Article View: net.bugs
Article #518Re: 2.10.3 unbatch bug and fix
From: Guy Harris
Date: Thu, 20 Mar 1986 18:45
Date: Thu, 20 Mar 1986 18:45
53 lines
2594 bytes
2594 bytes
> In article <243@micropro.UUCP> news@micropro.UUCP (USENET administrator) writes:
> >< while (strncmp(buf, "#! rnews ", 9)
> >< || strncmp(buf, "! rnews ", 8)) { /* kludge for bug */
> >---
> >> while (!strncmp(buf, "#! rnews ", 9)
> >> && !strncmp(buf, "! rnews ", 8)) { /* kludge for bug */
>
> Aren't these two the same by De Morgan's law?
No, the second is the complement of the first, by De Morgan's law. Using a
bastardized C notation, !(a || b) == (!a && !b), and therefore obviously
(a || b) != (!a && !b).
However, looking at the code to the 2.10.3 that comes with 4.3BSD beta, the
code around there reads
while (strncmp(buf, "#! rnews ", 9)) {
which means it's skipping over lines which do NOT begin with "#! rnews".
The original version, assuming it was a replacement for this line, skips
over lines which either don't begin with "#! rnews" or don't begin with "!
rnews", i.e. it never stops and skips over all lines. The replacement for
it, given the same assumption, skips over lines which both begin with "#!
rnews" and begin with "! rnews", i.e. it stops immediately. (If the first
and second tests are complements, since the second test is obviously always
FALSE the first test is obviously always TRUE.)
This is somewhat of an object lesson in Why Not To Treat "strcmp" As A
Function Returning A Boolean Value. It takes some effort to remember that
"strcmp(a, b)", treated as a Boolean value (i.e., 0/FALSE or non-0/TRUE) is
TRUE iff strings "a" and "b" are different. Now, since what we want is to
continue as long as the string neither begins with "#! rnews" or "! rnews",
we want
while (buf doesn't begin with "#! rnews"
&& buf doesn't begin with "! rnews") {
which translates as
while (strncmp(buf, "#! rnews", 9) != 0
&& strncmp(buf, "! rnews", 8) != 0)) {
since
string "a" <comparison op> string "b"
iff
strcmp(string "a", string "b") <comparison op> 0
--
Guy Harris
{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
guy@sun.arpa (yes, really)
Technical Details
Message-ID:
<3388@sun.uucp>Path:
arc1-ca.pugleaf.net!utzoo!linus!decvax!decwrl!sun!guyReferences:
<243@micropro.UUCP> <9980@ucla-cs.ARPA>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: arc1-ca.pugleaf.net!utzoo!linus!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs,net.news.b Subject: Re: 2.10.3 unbatch bug and fix Message-ID: <3388@sun.uucp> Date: Thu, 20-Mar-86 13:45:19 EST Article-I.D.: sun.3388 Posted: Thu Mar 20 13:45:19 1986 Date-Received: Sun, 30-Mar-86 06:42:13 EST References: <243@micropro.UUCP> <9980@ucla-cs.ARPA> Organization: Sun Microsystems, Inc. Lines: 53