🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.usg
Article #39

bug in lfind() - man page doesn't match code (Sys5.2)

#39
From: John Rogers
Date: Wed, 27 Jun 1984 17:00
59 lines
2271 bytes
Subject: bug in lfind() - man page doesn't match code

Index: lfind() /usr/src/lib/libc/port/gen/lfind.c Sys5.2

Description:
	The man page I have for "lfind" (a linear search routine,
	documented in "lsearch(3C)") indicates that lfind will return a
	NULL pointer if the datum is not found in the table.  In
	reality, it returns -1 cast to a pointer.

	This only applies to System V Release 2; the first release
	doesn't have lfind.  It's possible that other versions of the
	man page document lfind as returning -1; I only have the one
	printed in "UNIX System V Release 2.0 Programmer Reference
	Manual - DEC Processors".

Repeat-By:
	Run the following program:
-----------------------------cut here------------------------------
#include <stdio.h>
extern char *lfind();
extern char *lsearch();
extern int strcmp();

main() {
	char *ptr;
	char table[100];
	unsigned nel;		/* Number of elements in table. */
	(void) lsearch("foo", table, &nel, 4, strcmp);
	(void) lsearch("bar", table, &nel, 4, strcmp);

	ptr = lfind("xxx", table, &nel, 4, strcmp);
	if (ptr == (char *)NULL)
		(void) printf("This should print, but doesn't.\n");
	else if (ptr == (char *)-1)
		(void) printf("This shouldn't print, but does.\n");
}
------------------------cut here--------------------------------

Fix:
	Make the following changes to lfind.c:
diff -rs lfind.c- lfind.c
13a14,16
>  *
>  * jr  840627 - Changed to match the documentation, i.e return NULL rather
>  *		than -1 if the element can't be found.
15a19,20
> #include <stdio.h>
> 
32c37
< 	return (POINTER)(-1);
---
> 	return ( (POINTER) NULL );


-- 
				JR (John Rogers)
				...ihnp4!fortune!foros1!jr
				also fortune!jr and proper!jr
Technical Details
Message-ID: <200@foros1.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!linus!vaxine!wjh12!harvard!seismo!harpo!decvax!decwrl!amd70!fortune!foros1!jr

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 (Fortune) 6/7/84; site foros1.UUCP
Path: arc1-ca.pugleaf.net!utzoo!linus!vaxine!wjh12!harvard!seismo!harpo!decvax!decwrl!amd70!fortune!foros1!jr
From: jr@foros1.UUCP (John Rogers)
Newsgroups: net.bugs.usg,fs.sys5
Subject: bug in lfind() - man page doesn't match code (Sys5.2)
Message-ID: <200@foros1.UUCP>
Date: Wed, 27-Jun-84 13:00:45 EDT
Article-I.D.: foros1.200
Posted: Wed Jun 27 13:00:45 1984
Date-Received: Tue, 10-Jul-84 04:02:04 EDT
Lines: 59