Sun SPACK 是big-endian
host{/u/XXX/memLeak}:cat t.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
int *pi = 0;
long *pl = 0;
char *p1 = (char *)malloc(40); printf("p1 = %lx/n",p1);
memset(p1,0,40);
char * constStr="012345678901234567890123456789";
memcpy(p1,constStr,strlen(constStr));
char *p2 = (char *)malloc(40); printf("p2 = %lx/n",p2);
memset(p2,0,40);
pi = (int *)p2;
(*pi) = 0x12;
char *p3 = (char *)malloc(40); printf("p3 = %lx/n",p3);
memset(p3,0,40);
pi = (int *)p3;
(*pi) = 0x1234;
char *p4 = (char *)malloc(40); printf("p4 = %lx/n",p4);
memset(p4,0,40);
pl = (long*)p4;
(*pl) = 0x12345678;
printf("%s/n",0);
char *p5 = (char *)malloc(40); printf("p5 = %lx/n",p5);
memset(p5,0,40);
pl = (long*)p5;
(*pl) = 0x1234567890;
printf("%s/n",0);
printf("%s/n",0);
}
host{/u/XXX/memLeak}:cc -xarch=v9 t.c
host{/u/XXX/memLeak}:./a.out
p1 = 100100eb0
p2 = 100100ef0
p3 = 100100f30
Segmentation Fault(coredump)
host{/u/XXX/memLeak}:mdb core
Loading modules: [ libc.so.1 ld.so.1 ]
> 100100eb0/10X // char * p = "01234567890123456789";
0x100100eb0: 30313233 34353637 38393031 32333435 36373839
30313233 34353637 38390000 00000000 00000000
> 100100ef0/10X // int * p = 0x12;
0x100100ef0: 00000012 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000
> 100100f30/10X // int * p = 0x1234;
0x100100f30: 00001234 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000
>
> 100100f70/10X // long * p= 0x12345678;
0x100100f70: 00000000 12345678 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000
> 100100f70/10X // long * p = 0x1234567890;
0x100100f70: 00000012 34567890 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000
=====================
Memory address
---------> enlarge
|
|
V
enlarge