Bug 42422 - [libc] [patch] dbm_delete returns -1 instead of 1 when the key does not exist in the database.
Summary: [libc] [patch] dbm_delete returns -1 instead of 1 when the key does not exist...
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 4.6-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-09-04 21:30 UTC by GB Clark
Modified: 2015-03-23 19:57 UTC (History)
2 users (show)

See Also:


Attachments
db.patch.2.txt (404 bytes, text/plain)
2003-01-09 07:32 UTC, GB Clark
no flags Details
Update patch (457 bytes, patch)
2015-02-19 19:53 UTC, Pedro F. Giffuni
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description GB Clark 2002-09-04 21:30:01 UTC
dbm_delete is documented to return 1 if the key does NOT exist in the dbm file.
In lib/libc/db/ndmb.c it returns -1 or 0 only.

Fix: 

have dbm_delete in lib/libc/db/ndbm.c return status instead of the if switch.  The original db delete function returns the SAME status codes as dbm_delete according to the man page for db.
How-To-Repeat: Try to delete a non-exist key and get -1 instead of 1 using dbm_delete.
Comment 1 GB Clark 2003-01-09 07:32:27 UTC
Hello,

Here is a patch to correct the bug.

GB

-- 
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
            CTHULU for President - Why choose the lesser of two evils?
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-02-19 19:53:28 UTC
Created attachment 153190 [details]
Update patch
Comment 3 Xin LI freebsd_committer freebsd_triage 2015-02-20 00:54:05 UTC
(In reply to gclarkii from comment #0)
The proposed change is wrong, unfortunately.  It's the manual page that should be corrected instead.  To quote POSIX [1]:

"
RETURN VALUE

The dbm_store() and dbm_delete() functions shall return 0 when they succeed and a negative value when they fail.
"

So, we must return a negative value, and -1 is one of the valid return values.  1 on the other hand is not.

I have also checked Solaris and GDBM's implementation of the same interface and they all return -1.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/dbm_clearerr.html
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-02-20 01:31:47 UTC
A commit references this bug:

Author: pfg
Date: Fri Feb 20 01:31:11 UTC 2015
New revision: 279037
URL: https://svnweb.freebsd.org/changeset/base/279037

Log:
  dbm_delete(3) correct man page to match current behaviour.

  "The dbm_store() and dbm_delete() functions shall return 0 when they
  succeed and a negative value when they fail."

  Reference:
  http://pubs.opengroup.org/onlinepubs/9699919799/functions/dbm_clearerr.html

  PR:		42422
  Suggested by:	delphij
  MFC after:	3 days

Changes:
  head/lib/libc/db/man/dbm.3
Comment 5 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-02-20 01:33:23 UTC
(In reply to Xin LI from comment #3)

Good catch! POSIX doesn't seem to leave space for the description in the man page. I also confirmed with the NetBSD code.
Comment 6 commit-hook freebsd_committer freebsd_triage 2015-03-23 19:50:53 UTC
A commit references this bug:

Author: pfg
Date: Mon Mar 23 19:50:22 UTC 2015
New revision: 280394
URL: https://svnweb.freebsd.org/changeset/base/280394

Log:
  MFC	r279037:
  dbm_delete(3): correct man page to match current behaviour.

  "The dbm_store() and dbm_delete() functions shall return 0 when they
  succeed and a negative value when they fail."

  Reference:
  http://pubs.opengroup.org/onlinepubs/9699919799/functions/dbm_clearerr.html

  PR:		42422
  Suggested by:	delphij

Changes:
_U  stable/10/
  stable/10/lib/libc/db/man/dbm.3
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-03-23 19:53:55 UTC
A commit references this bug:

Author: pfg
Date: Mon Mar 23 19:53:38 UTC 2015
New revision: 280395
URL: https://svnweb.freebsd.org/changeset/base/280395

Log:
  MFC	r279037:
  dbm_delete(3): correct man page to match current behaviour.

  "The dbm_store() and dbm_delete() functions shall return 0 when they
  succeed and a negative value when they fail."

  Reference:
  http://pubs.opengroup.org/onlinepubs/9699919799/functions/dbm_clearerr.html

  PR:		42422
  Suggested by:	delphij

Changes:
_U  stable/9/lib/libc/
  stable/9/lib/libc/db/man/dbm.3
Comment 8 Pedro F. Giffuni freebsd_committer freebsd_triage 2015-03-23 19:57:11 UTC
Updated the manpage.