From 898f640e65879c793af392479b97dfcfb4fa2f53 Mon Sep 17 00:00:00 2001 From: Sakala Venkata Krishna Rohit Date: Mon, 27 Aug 2018 16:16:09 +0530 Subject: 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. --- upb/table.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'upb') diff --git a/upb/table.c b/upb/table.c index 61202b0..4239c6f 100644 --- a/upb/table.c +++ b/upb/table.c @@ -270,9 +270,10 @@ static size_t begin(const upb_table *t) { /* A simple "subclass" of upb_table that only adds a hash function for strings. */ static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { + uint32_t len = (uint32_t) k2.str.len; 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)); + memcpy(str, &len, sizeof(uint32_t)); memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); return (uintptr_t)str; } -- cgit v1.2.3