mirror of
https://github.com/yuzu-emu/breakpad.git
synced 2024-11-28 08:34:18 +01:00
Issue 42001: Breakpad Linux Dumper: remove compilation warnings in guid_creator.cc.
Building on Ubuntu 9.10 with the distributed compiler (GCC 4.4.1), we get warnings like the following: guid_creator.cc:56: warning: dereferencing type-punned pointer will break strict-aliasing rules It doesn't matter in this case, but there's no crying need to use reinterpret casts in an endian-dependent way when there are plenty of well-defined ways to get the same effect. a=jimblandy, r=nealsid git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@447 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
parent
4969cfc647
commit
07466260e2
@ -49,12 +49,26 @@ class GUIDGenerator {
|
|||||||
srandom(time(NULL));
|
srandom(time(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u_int32_t BytesToUInt32(const u_int8_t bytes[]) {
|
||||||
|
return ((u_int32_t) bytes[0]
|
||||||
|
| ((u_int32_t) bytes[1] << 8)
|
||||||
|
| ((u_int32_t) bytes[2] << 16)
|
||||||
|
| ((u_int32_t) bytes[3] << 24));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UInt32ToBytes(u_int8_t bytes[], u_int32_t n) {
|
||||||
|
bytes[0] = n & 0xff;
|
||||||
|
bytes[1] = (n >> 8) & 0xff;
|
||||||
|
bytes[2] = (n >> 16) & 0xff;
|
||||||
|
bytes[3] = (n >> 24) & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
bool CreateGUID(GUID *guid) const {
|
bool CreateGUID(GUID *guid) const {
|
||||||
guid->data1 = random();
|
guid->data1 = random();
|
||||||
guid->data2 = (u_int16_t)(random());
|
guid->data2 = (u_int16_t)(random());
|
||||||
guid->data3 = (u_int16_t)(random());
|
guid->data3 = (u_int16_t)(random());
|
||||||
*reinterpret_cast<u_int32_t*>(&guid->data4[0]) = random();
|
UInt32ToBytes(&guid->data4[0], random());
|
||||||
*reinterpret_cast<u_int32_t*>(&guid->data4[4]) = random();
|
UInt32ToBytes(&guid->data4[4], random());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -72,8 +86,8 @@ bool GUIDToString(const GUID *guid, char *buf, int buf_len) {
|
|||||||
assert(buf_len > kGUIDStringLength);
|
assert(buf_len > kGUIDStringLength);
|
||||||
int num = snprintf(buf, buf_len, kGUIDFormatString,
|
int num = snprintf(buf, buf_len, kGUIDFormatString,
|
||||||
guid->data1, guid->data2, guid->data3,
|
guid->data1, guid->data2, guid->data3,
|
||||||
*reinterpret_cast<const u_int32_t *>(&(guid->data4[0])),
|
GUIDGenerator::BytesToUInt32(&(guid->data4[0])),
|
||||||
*reinterpret_cast<const u_int32_t *>(&(guid->data4[4])));
|
GUIDGenerator::BytesToUInt32(&(guid->data4[4])));
|
||||||
if (num != kGUIDStringLength)
|
if (num != kGUIDStringLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user