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.
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?
Created attachment 153190 [details] Update patch
(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
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
(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.
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
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
Updated the manpage.