Subject: kern/13369: gcc inlines memcpy(3)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <minoura@netbsd.org>
List: netbsd-bugs
Date: 07/04/2001 10:03:23
>Number:         13369
>Category:       kern
>Synopsis:       gcc inlines memcpy(3)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 03 18:01:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Minoura Makoto
>Release:        20010612
>Organization:
Minoura Makoto <minoura@netbsd.org>
The NetBSD Project/Japan NetBSD Users' Group
>Environment:
System: NetBSD daisy 1.5W NetBSD 1.5W (DAISY) #190: Mon Jun 25 14:28:07 JST 2001 root@daisy:/usr/obj/sys/arch/i386/compile/DAISY i386
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
Architecture: i386
Machine: i386
>Description:
	gcc -O inlines the following memcpy(3) call (at least on i386):

#include <string.h>

extern char buf[];

void testfunc(char *src)
{
	memcpy(buf, src, 100);
}

	The inlined memcpy() gets insane when the two buffers are
	overlapping.

	On the other hand, kernel bcopy() is #define'ed as memcpy() in
	/sys/sys/systm.h.

	This might cause a problem that when the programmer
	wants to transfer overlapping strings using bcopy()
	they might be destroyed as a result.
>How-To-Repeat:
>Fix:
	- #define bcopy memcpy  ->  #define bcopy memmove in systm.h
>Release-Note:
>Audit-Trail:
>Unformatted: