diff options
-rw-r--r-- | tests/test_table.cc | 2 | ||||
-rw-r--r-- | upb/bindings/lua/upb.c | 17 |
2 files changed, 15 insertions, 4 deletions
diff --git a/tests/test_table.cc b/tests/test_table.cc index c70ef08..13b2330 100644 --- a/tests/test_table.cc +++ b/tests/test_table.cc @@ -276,7 +276,7 @@ void test_inttable(int32_t *keys, uint16_t num_entries, const char *desc) { if (x == INT_MAX) abort(); printf("%ld/s (%0.1f%% of upb)\n\n", (long)(i/total), i / upb_rand_i); upb_inttable_uninit(&table); - delete rand_order; + delete[] rand_order; } int32_t *get_contiguous_keys(int32_t num) { diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c index 2b05938..87b39e6 100644 --- a/upb/bindings/lua/upb.c +++ b/upb/bindings/lua/upb.c @@ -1341,10 +1341,21 @@ static size_t align_up(size_t val, size_t align) { return val % align == 0 ? val : val + align - (val % align); } -#define CHARPTR_AT(msg, ofs) ((char*)msg + sizeof(lupb_msg) + ofs) - /* If we always read/write as a consistent type to each value, this shouldn't - * violate aliasing. */ + * violate aliasing. + * + * Note that the slightly prettier option of: + * + * *(type*)(&msg->data[ofs]) + * + * ...is potentially more questionable wrt the C standard and aliasing. + * Does the expression &msg->data[ofs] "access the stored value"? If so, + * this would violate aliasing. So instead we use the expression: + * + * (char*)msg + sizeof(lupb_msg) + ofs + * + * ...which unambigiously is doing nothing but calculating a pointer address. */ +#define CHARPTR_AT(msg, ofs) ((char*)msg + sizeof(lupb_msg) + ofs) #define DEREF(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs) lupb_msg *lupb_msg_check(lua_State *L, int narg) { |