Memory Alignment Problem on Sun Sparcs

Hi, I try to marshal a unsigned int and a char * into a buffer, and then unmarshal them later to get them out. I need to put the char * in the front and unsigned int at the end of the buffer. However, my system always give me "BUS ERROR". I am using Sun Sparcs Sloris 2.10.

My code to marshal the data:

unsigned dev = 111;
unsigned inode = 222;

int s_docname = strlen(docname) + 1;
int s_key = s_docname + sizeof(unsigned) * 2;

keybuf = malloc(s_key);
memset(keybuf, 0, s_key);
memcpy(keybuf, docname, s_docname);
memcpy(keybuf + s_docname, &(dev), sizeof(unsigned));
memcpy(keybuf + s_docname + sizeof(unsigned), &(inode),
sizeof(unsigned));

My code to unmarshal the data:
char * docname = (char )key.data;
int s_docname = strlen(docname) + 1;
dev =
((unsigned *)((char *)key.data + s_docname));
inode = *((unsigned *)((char *)key.data + s_docname +
sizeof(unsigned)));

I can print the dev and inode out in dbx debugger by typing the same
code, but running the program always have the BUS error.

I realize this is a problems of memory alignement. s_docname has byte granularity, somehow I need to "round up" my s_docname by some suitable calculation. But I really don't know how to? Help is appreciated.

Please read the rules:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post where your goal is to get an answer more quickly.