mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-05 06:50:21 +02:00
Do not pass null for free, memcpy and memmove
* lib/jit_memory.c: Do not call free on NULL pointers. * include/lightning/jit_private.h, lib/jit_note.c, lib/lightning.c: Add a wrapper to memcpy and memmove to not actually call those functions with a zero size argument, and likely also a null src or dst.
This commit is contained in:
parent
a8c180a926
commit
0d9ac79a12
6 changed files with 52 additions and 19 deletions
|
@ -1,3 +1,12 @@
|
|||
2014-07-28 Paulo Andrade <pcpa@gnu.org>
|
||||
|
||||
* lib/jit_memory.c: Do not call free on NULL pointers.
|
||||
|
||||
* include/lightning/jit_private.h, lib/jit_note.c,
|
||||
lib/lightning.c: Add a wrapper to memcpy and memmove
|
||||
to not actually call those functions with a zero size
|
||||
argument, and likely also a null src or dst.
|
||||
|
||||
2014-07-27 Paulo Andrade <pcpa@gnu.org>
|
||||
|
||||
* include/lightning/jit_private.h, lib/jit_disasm.c,
|
||||
|
|
|
@ -592,6 +592,8 @@ extern void _jit_set_note(jit_state_t*, jit_note_t*, char*, int, jit_int32_t);
|
|||
#define jit_annotate() _jit_annotate(_jit)
|
||||
extern void _jit_annotate(jit_state_t*);
|
||||
|
||||
extern jit_pointer_t jit_memcpy(jit_pointer_t,jit_pointer_t,jit_word_t);
|
||||
extern jit_pointer_t jit_memmove(jit_pointer_t,jit_pointer_t,jit_word_t);
|
||||
extern void jit_alloc(jit_pointer_t*, jit_word_t);
|
||||
extern void jit_realloc(jit_pointer_t*, jit_word_t, jit_word_t);
|
||||
void jit_free(jit_pointer_t*);
|
||||
|
|
|
@ -1750,7 +1750,7 @@ _flush_consts(jit_state_t *_jit)
|
|||
_jitc->consts.size = _jitc->consts.length << 2;
|
||||
/* FIXME check will not overrun, otherwise, need to reallocate
|
||||
* code buffer and start over */
|
||||
memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
|
||||
jit_memcpy(_jitc->consts.data, _jitc->consts.values, _jitc->consts.size);
|
||||
_jit->pc.w += _jitc->consts.size;
|
||||
|
||||
#if DISASSEMBLER
|
||||
|
|
|
@ -38,6 +38,22 @@ static jit_free_func_ptr jit_free_ptr = jit_default_free_func;
|
|||
/*
|
||||
* Implementation
|
||||
*/
|
||||
jit_pointer_t
|
||||
jit_memcpy(jit_pointer_t dst, jit_pointer_t src, jit_word_t size)
|
||||
{
|
||||
if (size)
|
||||
return (memcpy(dst, src, size));
|
||||
return (dst);
|
||||
}
|
||||
|
||||
jit_pointer_t
|
||||
jit_memmove(jit_pointer_t dst, jit_pointer_t src , jit_word_t size)
|
||||
{
|
||||
if (size)
|
||||
return (memmove(dst, src, size));
|
||||
return (dst);
|
||||
}
|
||||
|
||||
void
|
||||
jit_set_memory_functions(jit_alloc_func_ptr alloc_ptr,
|
||||
jit_realloc_func_ptr realloc_ptr,
|
||||
|
@ -82,8 +98,10 @@ jit_realloc(jit_pointer_t *ptr, jit_word_t old_size, jit_word_t new_size)
|
|||
void
|
||||
jit_free(jit_pointer_t *ptr)
|
||||
{
|
||||
if (*ptr) {
|
||||
(*jit_free_ptr)(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void *
|
||||
|
|
|
@ -126,16 +126,17 @@ _jit_annotate(jit_state_t *_jit)
|
|||
note->size = _jit->pc.uc - note->code;
|
||||
|
||||
/* annotations may be very complex with conditions to extend
|
||||
* or ignore redudant notes, as well as add entries to earlier
|
||||
* or ignore redundant notes, as well as add entries to earlier
|
||||
* notes, so, relocate the information to the data buffer,
|
||||
* with likely over allocated reserved space */
|
||||
|
||||
/* relocate jit_line_t objects */
|
||||
for (note_offset = 0; note_offset < _jit->note.length; note_offset++) {
|
||||
note = _jit->note.ptr + note_offset;
|
||||
length = sizeof(jit_line_t) * note->length;
|
||||
if ((length = sizeof(jit_line_t) * note->length) == 0)
|
||||
continue;
|
||||
assert(_jitc->note.base + length < _jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, note->lines, length);
|
||||
jit_memcpy(_jitc->note.base, note->lines, length);
|
||||
jit_free((jit_pointer_t *)¬e->lines);
|
||||
note->lines = (jit_line_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
|
@ -149,13 +150,13 @@ _jit_annotate(jit_state_t *_jit)
|
|||
length = sizeof(jit_int32_t) * line->length;
|
||||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, line->linenos, length);
|
||||
jit_memcpy(_jitc->note.base, line->linenos, length);
|
||||
jit_free((jit_pointer_t *)&line->linenos);
|
||||
line->linenos = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
assert(_jitc->note.base + length <
|
||||
_jit->data.ptr + _jit->data.length);
|
||||
memcpy(_jitc->note.base, line->offsets, length);
|
||||
jit_memcpy(_jitc->note.base, line->offsets, length);
|
||||
jit_free((jit_pointer_t *)&line->offsets);
|
||||
line->offsets = (jit_int32_t *)_jitc->note.base;
|
||||
_jitc->note.base += length;
|
||||
|
@ -200,9 +201,9 @@ _jit_set_note(jit_state_t *_jit, jit_note_t *note,
|
|||
(line->length + 17) * sizeof(jit_int32_t));
|
||||
}
|
||||
if (index < note->length) {
|
||||
memmove(line->linenos + index + 1, line->linenos + index,
|
||||
jit_memmove(line->linenos + index + 1, line->linenos + index,
|
||||
sizeof(jit_int32_t) * (line->length - index));
|
||||
memmove(line->offsets + index + 1, line->offsets + index,
|
||||
jit_memmove(line->offsets + index + 1, line->offsets + index,
|
||||
sizeof(jit_int32_t) * (line->length - index));
|
||||
}
|
||||
line->linenos[index] = lineno;
|
||||
|
@ -280,7 +281,7 @@ new_line(jit_int32_t index, jit_note_t *note,
|
|||
(note->length + 17) * sizeof(jit_line_t));
|
||||
|
||||
if (index < note->length)
|
||||
memmove(note->lines + index + 1, note->lines + index,
|
||||
jit_memmove(note->lines + index + 1, note->lines + index,
|
||||
sizeof(jit_line_t) * (note->length - index));
|
||||
line = note->lines + index;
|
||||
++note->length;
|
||||
|
|
|
@ -610,7 +610,7 @@ _jit_data(jit_state_t *_jit, jit_pointer_t data,
|
|||
}
|
||||
node->u.w = _jitc->data.offset;
|
||||
node->v.w = length;
|
||||
memcpy(_jitc->data.ptr + _jitc->data.offset, data, length);
|
||||
jit_memcpy(_jitc->data.ptr + _jitc->data.offset, data, length);
|
||||
_jitc->data.offset += length;
|
||||
|
||||
node->next = _jitc->data.table[key];
|
||||
|
@ -1722,9 +1722,12 @@ _jit_dataset(jit_state_t *_jit)
|
|||
}
|
||||
|
||||
if (!_jitc->no_data)
|
||||
memcpy(_jit->data.ptr, _jitc->data.ptr, _jitc->data.offset);
|
||||
jit_memcpy(_jit->data.ptr, _jitc->data.ptr, _jitc->data.offset);
|
||||
|
||||
if (_jitc->no_note) {
|
||||
/* Space for one note is always allocated, so revert it here
|
||||
* if after jit_new_state was called, it is also requested to
|
||||
* not generate annotation information */
|
||||
_jit->note.length = 0;
|
||||
_jitc->note.size = 0;
|
||||
}
|
||||
|
@ -2581,7 +2584,7 @@ _simplify_movr(jit_state_t *_jit, jit_node_t *prev, jit_node_t *node,
|
|||
return (1);
|
||||
}
|
||||
if (_jitc->values[right].kind == jit_kind_word)
|
||||
memcpy(value, _jitc->values + right, sizeof(jit_value_t));
|
||||
jit_memcpy(value, _jitc->values + right, sizeof(jit_value_t));
|
||||
else {
|
||||
value->kind = jit_kind_register;
|
||||
value->base.q.l = right;
|
||||
|
@ -2630,14 +2633,14 @@ _simplify_movi(jit_state_t *_jit, jit_node_t *prev, jit_node_t *node,
|
|||
else
|
||||
node->code = jit_code_movr_d;
|
||||
node->v.w = offset;
|
||||
memcpy(value, _jitc->values + offset, sizeof(jit_value_t));
|
||||
jit_memcpy(value, _jitc->values + offset, sizeof(jit_value_t));
|
||||
++_jitc->gen[regno];
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
value->kind = kind;
|
||||
memcpy(&value->base.w, &node->v.w, size);
|
||||
jit_memcpy(&value->base.w, &node->v.w, size);
|
||||
++_jitc->gen[regno];
|
||||
|
||||
return (0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue