diff options
author | Sakala Venkata Krishna Rohit <rohitsakala@gmail.com> | 2018-08-27 16:16:09 +0530 |
---|---|---|
committer | Sakala Venkata Krishna Rohit <rohitsakala@gmail.com> | 2018-08-27 16:16:09 +0530 |
commit | 6522ae4fb3f567f3385a9d5ad7f67b015aeb22ac (patch) | |
tree | 72306b30039fda5b52c8167f2c0609e1c5d12477 | |
parent | 38d674e86f4d5b368e37e20d31a44c2924de6998 (diff) |
Bugfix on bigendianess by casting size_t to unint32_t
The reason for typecasting size_t to unint32_t is that size_t is 8 bytes and uint32_t is only 4 bytes.
If not typecasted Memcpy fails to copy the *correct* four bytes in big endian platforms.
-rw-r--r-- | upb/table.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/upb/table.c b/upb/table.c index 61202b0..99ae5c3 100644 --- a/upb/table.c +++ b/upb/table.c @@ -272,7 +272,8 @@ static size_t begin(const upb_table *t) { static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); if (str == NULL) return 0; - memcpy(str, &k2.str.len, sizeof(uint32_t)); + uint32_t len = (uint32_t) k2.str.len; + memcpy(str, &len, sizeof(uint32_t)); memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); return (uintptr_t)str; } |