diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-09-28 14:14:38 +0300 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-09-28 14:14:38 +0300 |
commit | 6d7519ee6cdd67480b35a4acea45e9a895ba51e2 (patch) | |
tree | 6642effb49d5bf5c3a1d263c5664bbc48e9187b3 /src/compiler | |
parent | b0ac4a02ad7bb4af546fa070191b099bdc9e3581 (diff) |
native.c: add some asserts and errors
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/native.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/compiler/native.c b/src/compiler/native.c index a7b1d04..47d49eb 100644 --- a/src/compiler/native.c +++ b/src/compiler/native.c @@ -12,18 +12,21 @@ static inline void* ptr_from_value(value_t ptr) { + assert(ptr); return (void*)(intptr_t)ptr; } static inline value_t value_from_ptr(void *ptr) { + assert(ptr); return (value_t)(intptr_t*)ptr; } static inline tree_t* upref(program_t *prg, tree_t *tree) { + assert(prg && tree); colm_tree_upref(prg, tree); return tree; } @@ -90,9 +93,13 @@ c_op_stack_pop(program_t *prg, tree_t **sp, value_t a) value_t c_strtoull(program_t *prg, tree_t **sp, str_t *a, value_t b) { + assert(a); + char buf[24] = {0}; - if ((value_t)a->value->length >= sizeof(buf)) - return -1; + if ((value_t)a->value->length >= sizeof(buf)) { + warnx("%s: input string is too large", __func__); + return -1; + } memcpy(buf, a->value->data, a->value->length); colm_tree_downref(prg, sp, (tree_t*)a); |