I've reduced the code to something simple that still segfaults (for me at least) on the memcpy line. It does the same thing with strcpy. I'm using GCC 3.3 on Gentoo Linux.
Code:char *funct( char *data, int bufsiz ) { char *temp = malloc( sizeof( char ) * bufsiz + 1 ); temp[ bufsiz ] = '\0'; assert( temp != NULL ); memcpy( data, temp, bufsiz ); free( temp ); return data; } int main( void ) { char *str = "hello world"; printf( "%s\n", funct( str, strlen( str ) ) ); return 0; }