[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 290/437: Do not pass null for free, memcpy and memmove
From: |
Andy Wingo |
Subject: |
[Guile-commits] 290/437: Do not pass null for free, memcpy and memmove |
Date: |
Mon, 2 Jul 2018 05:14:38 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit 0d9ac79a128524a57b951dc90f928e56531632b7
Author: pcpa <address@hidden>
Date: Tue Jul 29 10:29:49 2014 -0300
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.
---
ChangeLog | 9 +++++++++
include/lightning/jit_private.h | 2 ++
lib/jit_arm.c | 2 +-
lib/jit_memory.c | 22 ++++++++++++++++++++--
lib/jit_note.c | 23 ++++++++++++-----------
lib/lightning.c | 13 ++++++++-----
6 files changed, 52 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ea59d29..08e05bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-07-28 Paulo Andrade <address@hidden>
+
+ * 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 <address@hidden>
* include/lightning/jit_private.h, lib/jit_disasm.c,
diff --git a/include/lightning/jit_private.h b/include/lightning/jit_private.h
index 8de2c8b..1915ce2 100644
--- a/include/lightning/jit_private.h
+++ b/include/lightning/jit_private.h
@@ -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*);
diff --git a/lib/jit_arm.c b/lib/jit_arm.c
index e71feda..62d8e8a 100644
--- a/lib/jit_arm.c
+++ b/lib/jit_arm.c
@@ -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
diff --git a/lib/jit_memory.c b/lib/jit_memory.c
index 39cc549..b4193e4 100644
--- a/lib/jit_memory.c
+++ b/lib/jit_memory.c
@@ -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)
{
- (*jit_free_ptr)(*ptr);
- *ptr = NULL;
+ if (*ptr) {
+ (*jit_free_ptr)(*ptr);
+ *ptr = NULL;
+ }
}
static void *
diff --git a/lib/jit_note.c b/lib/jit_note.c
index 412eba3..f3d35fa 100644
--- a/lib/jit_note.c
+++ b/lib/jit_note.c
@@ -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,10 +201,10 @@ _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,
- sizeof(jit_int32_t) * (line->length - index));
- memmove(line->offsets + index + 1, line->offsets + index,
- sizeof(jit_int32_t) * (line->length - index));
+ jit_memmove(line->linenos + index + 1, line->linenos + index,
+ sizeof(jit_int32_t) * (line->length - index));
+ jit_memmove(line->offsets + index + 1, line->offsets + index,
+ sizeof(jit_int32_t) * (line->length - index));
}
line->linenos[index] = lineno;
line->offsets[index] = offset;
@@ -280,8 +281,8 @@ 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,
- sizeof(jit_line_t) * (note->length - index));
+ jit_memmove(note->lines + index + 1, note->lines + index,
+ sizeof(jit_line_t) * (note->length - index));
line = note->lines + index;
++note->length;
diff --git a/lib/lightning.c b/lib/lightning.c
index 9a6d16f..ba18396 100644
--- a/lib/lightning.c
+++ b/lib/lightning.c
@@ -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);
- [Guile-commits] 328/437: Update THANKS file, (continued)
- [Guile-commits] 328/437: Update THANKS file, Andy Wingo, 2018/07/02
- [Guile-commits] 129/437: Remove previous macro files as they are no longer used., Andy Wingo, 2018/07/02
- [Guile-commits] 09/437: add autotools-generated files, Andy Wingo, 2018/07/02
- [Guile-commits] 69/437: implement long mul/div/mod for x86-64, Andy Wingo, 2018/07/02
- [Guile-commits] 162/437: Correct regressions with --with-float={soft, softfp} in the arm backend, Andy Wingo, 2018/07/02
- [Guile-commits] 377/437: aarch64: Add initial jit_va_ calls to aarch64, Andy Wingo, 2018/07/02
- [Guile-commits] 298/437: ARM: Correct wrong table of instruction sizes in software float, Andy Wingo, 2018/07/02
- [Guile-commits] 99/437: always set and replace lightning_frag, Andy Wingo, 2018/07/02
- [Guile-commits] 336/437: Correct bogus git entry, Andy Wingo, 2018/07/02
- [Guile-commits] 282/437: Document the lightning customization functions., Andy Wingo, 2018/07/02
- [Guile-commits] 290/437: Do not pass null for free, memcpy and memmove,
Andy Wingo <=
- [Guile-commits] 249/437: Make jit_get_note a public interface., Andy Wingo, 2018/07/02
- [Guile-commits] 299/437: ALPHA: Correct class of argument float registers, Andy Wingo, 2018/07/02
- [Guile-commits] 426/437: Remove empty lightning m4 directory, Andy Wingo, 2018/07/02
- [Guile-commits] 379/437: s390: Add initial jit_va_ calls to s390, Andy Wingo, 2018/07/02
- [Guile-commits] 431/437: Always enable assertions in embedded lightning, Andy Wingo, 2018/07/02
- [Guile-commits] 365/437: X86: Correct load and store in the x32 abi, Andy Wingo, 2018/07/02
- [Guile-commits] 190/437: Finish sparc port., Andy Wingo, 2018/07/02
- [Guile-commits] 436/437: Wire JIT availability check into Guile configure, Andy Wingo, 2018/07/02
- [Guile-commits] 350/437: Correct typo., Andy Wingo, 2018/07/02
- [Guile-commits] 424/437: Beginnings of build integration of lightning and guile, Andy Wingo, 2018/07/02