Bug 216872 - Behavior for hsearch_r is flip-flopped per documentation (behavior matches Linux, docs match NetBSD)
Summary: Behavior for hsearch_r is flip-flopped per documentation (behavior matches Li...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-07 02:53 UTC by Enji Cooper
Modified: 2018-01-08 04:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer freebsd_triage 2017-02-07 02:53:30 UTC
It seems that we grabbed the manpages for hcreate*(3) from NetBSD, but the actual implementation is patterned after Linux. In particular, .../contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c tests that text code from a non-existent item when action=FIND, but the value it tests it against is 1 (Linux -> non-zero -> error), not 0 (NetBSD -> zero -> error). I opened a bug for the non-intuitive behavior on NetBSD here: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=51957 .

The documentation should match the implementation, at bare minimum. Whether or not the implementation matches Linux or NetBSD is a point of debate.
Comment 1 commit-hook freebsd_committer freebsd_triage 2017-02-07 02:58:08 UTC
A commit references this bug:

Author: ngie
Date: Tue Feb  7 02:57:12 UTC 2017
New revision: 313375
URL: https://svnweb.freebsd.org/changeset/base/313375

Log:
  Expect :hsearch_r_nonexistent to fail on FreeBSD

  The docs and the behavior mismatch; as noted in the bug, the behavior
  for hsearch_r matches Linux, whereas the docs seem to match NetBSD
  requirements wise.

  PR:	216872

Changes:
  projects/netbsd-tests-upstream-01-2017/contrib/netbsd-tests/lib/libc/stdlib/t_hsearch.c
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2017-02-07 15:43:31 UTC
(In reply to Ngie Cooper from comment #0)
Some historical context as it seems to have been lost somehow:
The original implementation of hsearch(3) for FreeBSD up to 10.x release, was indeed based on NetBSD. For the case of hsearch_r we adopted hsearch_r but the NetBSD code never made it into a release as ed@ wrote a new implementation in r292767.

The implementation for hcreate(3) functions should match POSIX. hsearch_r(3) is a glibc extension.
Comment 3 Eitan Adler freebsd_committer freebsd_triage 2018-01-08 04:14:34 UTC
For the following conditions
Product: Base System, Documentation Status: New, Open, In Progress, UNCONFIRMED 
Assignee: Former FreeBSD committer 

Reset to default assignee. Reset status to "Open".