🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #330

Re: tsearch(3) and tfind return incorrect pointers

#330
From: Brandon S. Allbery KB8JRR
Date: Thu, 24 Jan 1991 01:56
31 lines
2029 bytes
As quoted from <888@amix.commodore.com> by ford@amix.commodore.com (Mike "Ford" Ditto):
+---------------
| 						    If there is	a
|      datum in the tree equal to	*key (the  value  pointed  to  by
|      key), a pointer to	this found datum is returned.  Otherwise,
|      *key is inserted,	and  a	pointer	 to  it	 returned.
+---------------

It does not say that "key" is returned, it says that "*key is inserted and a
pointer to it is returned".  This is perfectly consistent with what in fact
happens --- it does *not* say that the pointer is the same one that is passed
in, note! --- and I have used tsearch/tfind in a number of programs without
problems.  Admittedly, the manpage could be more clearly worded, but it is
correct as it is.

+---------------
| According to that, both functions should return the exact same key
| pointer which was passed to tsearch originally.  But what they really
+---------------

No, this is *not* what the quoted manpage says!  The manpage neither confirms
nor denies that your key might be *copied* and a pointer to the copy returned.
But if tsearch() were supposed to return "key", the manpage would say so; it
would not use the wording that it in fact does.

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY
Technical Details
Message-ID: <1991Jan24.015606.9787@NCoast.ORG>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!ukma!usenet.ins.cwru.edu!ncoast!allbery
References: <888@amix.commodore.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!wuarchive!ukma!usenet.ins.cwru.edu!ncoast!allbery
From: allbery@NCoast.ORG (Brandon S. Allbery KB8JRR)
Newsgroups: comp.bugs.sys5
Subject: Re: tsearch(3) and tfind return incorrect pointers
Message-ID: <1991Jan24.015606.9787@NCoast.ORG>
Date: 24 Jan 91 01:56:06 GMT
References: <888@amix.commodore.com>
Reply-To: allbery@ncoast.ORG (Brandon S. Allbery KB8JRR)
Followup-To: comp.bugs.sys5
Organization: North Coast Computer Resources (ncoast)
Lines: 31