use const for memory_corruption_check_small

This currently causes a warning (treated as an error) on Android where
malloc_usable_size uses a const pointer.
pull/109/head
Daniel Micay 2020-04-30 16:06:32 -04:00
parent 029a2edf28
commit b672316bc7
1 changed files with 5 additions and 5 deletions

View File

@ -418,8 +418,8 @@ static bool is_free_slab(struct slab_metadata *metadata) {
#endif #endif
} }
static struct slab_metadata *get_metadata(struct size_class *c, void *p) { static struct slab_metadata *get_metadata(struct size_class *c, const void *p) {
size_t offset = (char *)p - (char *)c->class_region_start; size_t offset = (const char *)p - (const char *)c->class_region_start;
size_t index = libdivide_u64_do(offset, &c->slab_size_divisor); size_t index = libdivide_u64_do(offset, &c->slab_size_divisor);
// still caught without this check either as a read access violation or "double free" // still caught without this check either as a read access violation or "double free"
if (index >= c->metadata_allocated) { if (index >= c->metadata_allocated) {
@ -1558,7 +1558,7 @@ EXPORT void h_free_sized(void *p, size_t expected_size) {
thread_seal_metadata(); thread_seal_metadata();
} }
static inline void memory_corruption_check_small(void *p) { static inline void memory_corruption_check_small(const void *p) {
struct slab_size_class_info size_class_info = slab_size_class(p); struct slab_size_class_info size_class_info = slab_size_class(p);
size_t class = size_class_info.class; size_t class = size_class_info.class;
struct size_class *c = &ro.size_class_metadata[size_class_info.arena][class]; struct size_class *c = &ro.size_class_metadata[size_class_info.arena][class];
@ -1573,7 +1573,7 @@ static inline void memory_corruption_check_small(void *p) {
struct slab_metadata *metadata = get_metadata(c, p); struct slab_metadata *metadata = get_metadata(c, p);
void *slab = get_slab(c, slab_size, metadata); void *slab = get_slab(c, slab_size, metadata);
size_t slot = libdivide_u32_do((char *)p - (char *)slab, &c->size_divisor); size_t slot = libdivide_u32_do((const char *)p - (const char *)slab, &c->size_divisor);
if (slot_pointer(size, slab, slot) != p) { if (slot_pointer(size, slab, slot) != p) {
fatal_error("invalid unaligned malloc_usable_size"); fatal_error("invalid unaligned malloc_usable_size");
@ -1585,7 +1585,7 @@ static inline void memory_corruption_check_small(void *p) {
if (!is_zero_size && canary_size) { if (!is_zero_size && canary_size) {
u64 canary_value; u64 canary_value;
memcpy(&canary_value, (char *)p + size - canary_size, canary_size); memcpy(&canary_value, (const char *)p + size - canary_size, canary_size);
if (unlikely(canary_value != metadata->canary_value)) { if (unlikely(canary_value != metadata->canary_value)) {
fatal_error("canary corrupted"); fatal_error("canary corrupted");
} }