tsearch(3) and tfind return incorrect pointers

Brandon S. Allbery KB8JRR allbery at NCoast.ORG
Thu Jan 24 12:56:06 AEST 1991


As quoted from <888 at amix.commodore.com> by ford at 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 at 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



More information about the Comp.bugs.sys5 mailing list