Skip to content

Commit 14a5b23

Browse files
author
Tor Didriksen
committed
Bug#27660330 ADD SUPPORT FOR CLANG UBSAN lf_alloc-pin
Remove function pointer casting in lf_alloc-pin mysys/lf_alloc-pin.cc:330:5: runtime error: call to function alloc_free(unsigned char*, unsigned char*, LF_ALLOCATOR*) through pointer to incorrect function type 'void (*)(void *, void *, void *)' mysys/lf_alloc-pin.cc:354: note: alloc_free(unsigned char*, unsigned char*, LF_ALLOCATOR*) defined here #0 0x9a7a297 in lf_pinbox_real_free(LF_PINS*) mysys/lf_alloc-pin.cc:330:5 Change-Id: Ib00ea768670971a4851e8f250a7bb211ab9ffafb
1 parent 71a929d commit 14a5b23

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

mysys/lf_alloc-pin.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* QQ: TODO multi-pinbox */
2-
/* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
2+
/* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -280,7 +280,9 @@ struct st_match_and_save_arg {
280280
to a new purgatory. At the end, the old purgatory will contain
281281
pointers not pinned by any thread.
282282
*/
283-
static int match_and_save(LF_PINS *el, struct st_match_and_save_arg *arg) {
283+
static int match_and_save(void *v_el, void *v_arg) {
284+
LF_PINS *el = static_cast<LF_PINS *>(v_el);
285+
st_match_and_save_arg *arg = static_cast<st_match_and_save_arg *>(v_arg);
284286
int i;
285287
LF_PINS *el_end = el + LF_DYNARRAY_LEVEL_LENGTH;
286288
for (; el < el_end; el++) {
@@ -320,8 +322,7 @@ static void lf_pinbox_real_free(LF_PINS *pins) {
320322
pins->purgatory = NULL;
321323
pins->purgatory_count = 0;
322324

323-
lf_dynarray_iterate(&pinbox->pinarray, (lf_dynarray_func)match_and_save,
324-
&arg);
325+
lf_dynarray_iterate(&pinbox->pinarray, match_and_save, &arg);
325326

326327
if (arg.old_purgatory) {
327328
/* Some objects in the old purgatory were not pinned, free them. */
@@ -351,7 +352,10 @@ LF_REQUIRE_PINS(1)
351352
'first' and 'last' are the ends of the linked list of nodes:
352353
first->el->el->....->el->last. Use first==last to free only one element.
353354
*/
354-
static void alloc_free(uchar *first, uchar *last, LF_ALLOCATOR *allocator) {
355+
static void alloc_free(void *v_first, void *v_last, void *v_allocator) {
356+
uchar *first = static_cast<uchar *>(v_first);
357+
uchar *last = static_cast<uchar *>(v_last);
358+
LF_ALLOCATOR *allocator = static_cast<LF_ALLOCATOR *>(v_allocator);
355359
uchar *node = allocator->top;
356360
do {
357361
anext_node(last) = node;
@@ -377,8 +381,7 @@ static void alloc_free(uchar *first, uchar *last, LF_ALLOCATOR *allocator) {
377381

378382
void lf_alloc_init2(LF_ALLOCATOR *allocator, uint size, uint free_ptr_offset,
379383
lf_allocator_func *ctor, lf_allocator_func *dtor) {
380-
lf_pinbox_init(&allocator->pinbox, free_ptr_offset,
381-
(lf_pinbox_free_func *)alloc_free, allocator);
384+
lf_pinbox_init(&allocator->pinbox, free_ptr_offset, alloc_free, allocator);
382385
allocator->top = 0;
383386
allocator->mallocs = 0;
384387
allocator->element_size = size;

0 commit comments

Comments
 (0)