amazing memcpy bug on Solaris

mhalibard@csafe.com mhalibard@csafe.com
Fri Oct 1 00:00:00 GMT 1999


I have encountered a truly amazing bug when compiling with gcc on
solaris. I would be grateful to anybody who can explain what on earth
is going wrong.

// compiled by typing "gcc main.cpp -o main"
#include <stdio.h>
#include <string>

// this one crashes on memcpy with segmentation fault 
void main()
{
	char* buffer_ptr = "abcdefghijklmnop";
	long * outBuff = (long *)malloc(4);
	memcpy(buffer_ptr, outBuff, 1); 
}

// this one is fine
void main()
{
	char buffer_ptr[17];
	strcpy(buffer_ptr,"abcdefghijklmnop");
	long * outBuff = (long *)malloc(4);
	memcpy(buffer_ptr, outBuff, 1); 
}



More information about the Gcc-help mailing list