Bus Address Crash in ckh unit test
Christopher Ferris
cferris at google.com
Mon Feb 1 15:51:20 PST 2016
When I compiled the ckh unit test with a newer version of clang, it was
crashing. I tracked the problem down to an implicit assumption that a value
passed to chk_search is 4 byte aligned. Specifically, the code in
test/unit/ckh.c, the test test_count_insert_search_remove, makes this call:
assert_true(ckh_search(&ckh, missing, NULL, NULL),
"Unexpected ckh_search() success");
The problem is that the definition of missing is:
char *missing = "A string not in the hash table.";
Which means missing is not guaranteed to be of any alignment.
I'm not sure on what platforms jemalloc needs to be compiled, so I think
that something like this:
#define HASH_TABLE_STRING "A string not in the hash table."
union { char char_data[sizeof(HASH_TABLE_STRING)]; uint32_t uint_data; }
missing;
memcpy(missing.char_data, HASH_TABLE_STRING, sizeof(HASH_TABLE_STRING));
.
.
.
assert_true(ckh_search(&ckh, missing.char_data, NULL, NULL),
"Unexpected ckh_search() success");
Would guarantee the needed alignment.
Does this seem reasonable?
Christopher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jemalloc.net/mailman/jemalloc-discuss/attachments/20160201/3a584bbc/attachment.html>
More information about the jemalloc-discuss
mailing list