Subject: lib/5835: shmat(2) returns -1 on errors but the manual says NULL
To: None <gnats-bugs@gnats.netbsd.org>
From: None <yasufu-i@is.aist-nara.ac.jp>
List: netbsd-bugs
Date: 07/25/1998 05:25:54
>Number:         5835
>Category:       lib
>Synopsis:       shmat(2) returns -1 on errors but the manual says NULL
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 24 13:35:01 1998
>Last-Modified:
>Originator:     ITOH Yasufumi
>Organization:
	Nara Institute of Science and Technology, Nara, Japan
>Release:        1.3F (July 24, 1998)
>Environment:
System: NetBSD libble.my.domain 1.3F NetBSD 1.3F (LIBBLE) #1: Sat Jul 25 03:56:40 JST 1998 itohy@libble.my.domain:/usr/src/sys/arch/alpha/compile/LIBBLE alpha


>Description:
	The online manual shmat(2) says the function returns NULL
	on errors, but actually it returns -1.

	I'm not sure which is wrong, but the SVR4 manual says it returns -1,
	the manual would be wrong.

>How-To-Repeat:
	Read the manual shmat(2),
	and try the following program, which prints
	0xffffffffffffffff (on alpha) or 0xffffffff.

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>

int
main()
{
	void *addr;

	addr = shmat(-1, 0, 0);		/* try with illegal id */
	perror("shmat");
	printf("%p\n", addr);
	return 0;
}

>Fix:

diff -u lib/libc/sys/shmat.2.orig lib/libc/sys/shmat.2
--- lib/libc/sys/shmat.2.orig	Fri May  8 20:14:51 1998
+++ lib/libc/sys/shmat.2	Sat Jul 25 05:07:25 1998
@@ -87,8 +87,7 @@
 .Sh RETURN VALUES
 .Fn shmat
 returns the address at which the shared memory segment has been mapped into
-the calling process' address space when successful, otherwise it returns
-.Dv NULL .
+the calling process' address space when successful, otherwise it returns -1.
 .Fn shmdt
 returns 0 on successful completion. Otherwise, a value of -1 is returned,
 and the global variable
>Audit-Trail:
>Unformatted: