Hi,
With the following piece of code:
typedef struct
{
char fileName[ 1024];
time_t deleteTime;
} file_item_t;
....
....
setEntry(char *fileName)
{
file_item_t file;
memset( &file, 0x00, sizeof( file_item_t ));
memcpy( file.fileName,
fileName,
sizeof( file.fileName ) - 1 );
...
...
When the function is called, it runs OK on a SPARC machine but segfaults on an i386 both running Solaris 10.
fileName
is a nul-terminated string about 30 chars let's say.
It appears that an attempt to read beyond the range of the fileName
using memcpy()
triggers a segmentation fault on some systems.
It's legacy code and easily correctable. But what I would like to know is about the underlying characteristics that can result in this failing or not. Is it related to read violation on the stack? Some boundary crossing? It is related to memory segmentation and is it just a case of chance (depending on how memory segmentation/paging is done by memory management and OS.) that it can fail or not.
Thanks a lot.