I have a structure as:
//GUID structure
typedef struct {
var8 octet[16];
} GPTGUID_t;
And a long #define as:
#define PTYPE_MRP_UPPER 0x4db80b5ce3c9e316ULL
#define PTYPE_MRP_LOWER 0xae1502f02df97d81ULL
I wish to copy UPPER part in octet 0 to 7 and LOWER in 8 to 15.
Unfortunately all attempts including memcpy has failed and given segfault.
I tried something as:
strcpy(guid.octet[0], PTYPE_MRP_UPPER);
strcpy(guid.octet[8], PTYPE_MRP_LOWER);
And also,
memcpy(guid.octet[0], PTYPE_MRP_UPPER, sizeof(PTYPE_MRP_UPPER));
memcpy(guid.octet[8], PTYPE_MRP_LOWER, sizeof(PTYPE_MRP_LOWER));
Both have failed.
Just as a side note:
typedef unsigned char var8;
typedef unsigned short var16;
typedef unsigned int var32;
However, I am able to extract the individual octets as:
memcpy( guid.octet, pHdr->partTypeGUID, sizeof(GPTGUID_t));//copy the partitionTypeGUID
p1 = getvar64(guid.octet[0]);
p2 = getvar64(guid.octet[8]);
where, #define getvar64(x) (*(var64*)(&x))
The value
0x4db80b5ce3c9e316ULLis not a string, sostrcpytreats is as a pointer and with a value like that it’s pointing way wrong.You also can’t use
strcpyas it copies until it finds a zero byte (the character'\0'). Usememcpyinstead.You also doesn’t pass pointers to the
memcpyfunction, but values. You should turn on more warnings because the compiler will not like it, but not enough to make it an error apparently.Try to call
memcpylike this: