diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-26 11:09:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 11:09:28 +0100 |
commit | 58e1da9b7dd69af0f32fb2a70c1808dce8c51733 (patch) | |
tree | 3150ccd20772ee2406d3024a9b930f6051f6c028 | |
parent | 134f575064c8a454354aead852533104642d2d5a (diff) | |
parent | 3f6d1998b60e2778730a925d2b761db3b54979fe (diff) |
Merge pull request #35 from jow-/various-fixes
Various fixes
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | tests/custom/04_bugs/01_try_catch_stack_mismatch (renamed from tests/custom/03_bugs/01_try_catch_stack_mismatch) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/02_array_pop_use_after_free (renamed from tests/custom/03_bugs/02_array_pop_use_after_free) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/03_switch_fallthrough_miscompilation (renamed from tests/custom/03_bugs/03_switch_fallthrough_miscompilation) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/04_property_set_abort (renamed from tests/custom/03_bugs/04_property_set_abort) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/05_duplicate_ressource_type (renamed from tests/custom/03_bugs/05_duplicate_ressource_type) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/06_lexer_escape_at_boundary (renamed from tests/custom/03_bugs/06_lexer_escape_at_boundary) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/07_lexer_overlong_lines (renamed from tests/custom/03_bugs/07_lexer_overlong_lines) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/08_compiler_arrow_fn_expressions (renamed from tests/custom/03_bugs/08_compiler_arrow_fn_expressions) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/09_reject_invalid_array_indexes (renamed from tests/custom/03_bugs/09_reject_invalid_array_indexes) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/10_break_stack_mismatch (renamed from tests/custom/03_bugs/10_break_stack_mismatch) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/11_switch_stack_mismatch (renamed from tests/custom/03_bugs/11_switch_stack_mismatch) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/12_altblock_stack_mismatch (renamed from tests/custom/03_bugs/12_altblock_stack_mismatch) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/13_split_by_string_leading_trailing (renamed from tests/custom/03_bugs/13_split_by_string_leading_trailing) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/14_incomplete_expression_at_eof (renamed from tests/custom/03_bugs/14_incomplete_expression_at_eof) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/15_segfault_on_prefix_increment (renamed from tests/custom/03_bugs/15_segfault_on_prefix_increment) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/16_hang_on_regexp_at_eof (renamed from tests/custom/03_bugs/16_hang_on_regexp_at_eof) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/17_hang_on_unclosed_expression_block (renamed from tests/custom/03_bugs/17_hang_on_unclosed_expression_block) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/18_hang_on_line_comments_at_eof (renamed from tests/custom/03_bugs/18_hang_on_line_comments_at_eof) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/19_truncated_format_string (renamed from tests/custom/03_bugs/19_truncated_format_string) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/20_use_strict_stack_mismatch (renamed from tests/custom/03_bugs/20_use_strict_stack_mismatch) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/21_compiler_parenthesized_prop_keyword (renamed from tests/custom/03_bugs/21_compiler_parenthesized_prop_keyword) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/22_compiler_break_continue_scoping (renamed from tests/custom/03_bugs/22_compiler_break_continue_scoping) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/23_compiler_parenthesized_division (renamed from tests/custom/03_bugs/23_compiler_parenthesized_division) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/24_compiler_local_for_loop_declaration (renamed from tests/custom/03_bugs/24_compiler_local_for_loop_declaration) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/25_lexer_shifted_offsets (renamed from tests/custom/03_bugs/25_lexer_shifted_offsets) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/26_compiler_jmp_to_zero (renamed from tests/custom/03_bugs/26_compiler_jmp_to_zero) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/27_invalid_sparse_array_set (renamed from tests/custom/03_bugs/26_invalid_sparse_array_set) | 0 | ||||
-rw-r--r-- | tests/custom/04_bugs/28_null_equality | 31 | ||||
-rw-r--r-- | tests/custom/04_bugs/29_empty_string_as_number | 17 | ||||
-rwxr-xr-x | tests/custom/run_tests.sh | 30 | ||||
-rw-r--r-- | types.c | 9 | ||||
-rw-r--r-- | vallist.c | 6 |
33 files changed, 85 insertions, 10 deletions
@@ -445,7 +445,7 @@ uc_exists(uc_vm_t *vm, size_t nargs) char *k; if (ucv_type(obj) != UC_OBJECT) - return false; + return ucv_boolean_new(false); k = uc_cast_string(vm, &key, &freeable); diff --git a/tests/custom/03_bugs/01_try_catch_stack_mismatch b/tests/custom/04_bugs/01_try_catch_stack_mismatch index f6e5a0a..f6e5a0a 100644 --- a/tests/custom/03_bugs/01_try_catch_stack_mismatch +++ b/tests/custom/04_bugs/01_try_catch_stack_mismatch diff --git a/tests/custom/03_bugs/02_array_pop_use_after_free b/tests/custom/04_bugs/02_array_pop_use_after_free index 22f63ff..22f63ff 100644 --- a/tests/custom/03_bugs/02_array_pop_use_after_free +++ b/tests/custom/04_bugs/02_array_pop_use_after_free diff --git a/tests/custom/03_bugs/03_switch_fallthrough_miscompilation b/tests/custom/04_bugs/03_switch_fallthrough_miscompilation index 3e6410e..3e6410e 100644 --- a/tests/custom/03_bugs/03_switch_fallthrough_miscompilation +++ b/tests/custom/04_bugs/03_switch_fallthrough_miscompilation diff --git a/tests/custom/03_bugs/04_property_set_abort b/tests/custom/04_bugs/04_property_set_abort index 8af477f..8af477f 100644 --- a/tests/custom/03_bugs/04_property_set_abort +++ b/tests/custom/04_bugs/04_property_set_abort diff --git a/tests/custom/03_bugs/05_duplicate_ressource_type b/tests/custom/04_bugs/05_duplicate_ressource_type index 21166b2..21166b2 100644 --- a/tests/custom/03_bugs/05_duplicate_ressource_type +++ b/tests/custom/04_bugs/05_duplicate_ressource_type diff --git a/tests/custom/03_bugs/06_lexer_escape_at_boundary b/tests/custom/04_bugs/06_lexer_escape_at_boundary index e80b0a1..e80b0a1 100644 --- a/tests/custom/03_bugs/06_lexer_escape_at_boundary +++ b/tests/custom/04_bugs/06_lexer_escape_at_boundary diff --git a/tests/custom/03_bugs/07_lexer_overlong_lines b/tests/custom/04_bugs/07_lexer_overlong_lines index d2dd3be..d2dd3be 100644 --- a/tests/custom/03_bugs/07_lexer_overlong_lines +++ b/tests/custom/04_bugs/07_lexer_overlong_lines diff --git a/tests/custom/03_bugs/08_compiler_arrow_fn_expressions b/tests/custom/04_bugs/08_compiler_arrow_fn_expressions index 5cd8960..5cd8960 100644 --- a/tests/custom/03_bugs/08_compiler_arrow_fn_expressions +++ b/tests/custom/04_bugs/08_compiler_arrow_fn_expressions diff --git a/tests/custom/03_bugs/09_reject_invalid_array_indexes b/tests/custom/04_bugs/09_reject_invalid_array_indexes index a7e5272..a7e5272 100644 --- a/tests/custom/03_bugs/09_reject_invalid_array_indexes +++ b/tests/custom/04_bugs/09_reject_invalid_array_indexes diff --git a/tests/custom/03_bugs/10_break_stack_mismatch b/tests/custom/04_bugs/10_break_stack_mismatch index ae16dac..ae16dac 100644 --- a/tests/custom/03_bugs/10_break_stack_mismatch +++ b/tests/custom/04_bugs/10_break_stack_mismatch diff --git a/tests/custom/03_bugs/11_switch_stack_mismatch b/tests/custom/04_bugs/11_switch_stack_mismatch index cc3b41a..cc3b41a 100644 --- a/tests/custom/03_bugs/11_switch_stack_mismatch +++ b/tests/custom/04_bugs/11_switch_stack_mismatch diff --git a/tests/custom/03_bugs/12_altblock_stack_mismatch b/tests/custom/04_bugs/12_altblock_stack_mismatch index e350660..e350660 100644 --- a/tests/custom/03_bugs/12_altblock_stack_mismatch +++ b/tests/custom/04_bugs/12_altblock_stack_mismatch diff --git a/tests/custom/03_bugs/13_split_by_string_leading_trailing b/tests/custom/04_bugs/13_split_by_string_leading_trailing index 10a6062..10a6062 100644 --- a/tests/custom/03_bugs/13_split_by_string_leading_trailing +++ b/tests/custom/04_bugs/13_split_by_string_leading_trailing diff --git a/tests/custom/03_bugs/14_incomplete_expression_at_eof b/tests/custom/04_bugs/14_incomplete_expression_at_eof index 474e87c..474e87c 100644 --- a/tests/custom/03_bugs/14_incomplete_expression_at_eof +++ b/tests/custom/04_bugs/14_incomplete_expression_at_eof diff --git a/tests/custom/03_bugs/15_segfault_on_prefix_increment b/tests/custom/04_bugs/15_segfault_on_prefix_increment index 280b680..280b680 100644 --- a/tests/custom/03_bugs/15_segfault_on_prefix_increment +++ b/tests/custom/04_bugs/15_segfault_on_prefix_increment diff --git a/tests/custom/03_bugs/16_hang_on_regexp_at_eof b/tests/custom/04_bugs/16_hang_on_regexp_at_eof index d8702ca..d8702ca 100644 --- a/tests/custom/03_bugs/16_hang_on_regexp_at_eof +++ b/tests/custom/04_bugs/16_hang_on_regexp_at_eof diff --git a/tests/custom/03_bugs/17_hang_on_unclosed_expression_block b/tests/custom/04_bugs/17_hang_on_unclosed_expression_block index 25128bb..25128bb 100644 --- a/tests/custom/03_bugs/17_hang_on_unclosed_expression_block +++ b/tests/custom/04_bugs/17_hang_on_unclosed_expression_block diff --git a/tests/custom/03_bugs/18_hang_on_line_comments_at_eof b/tests/custom/04_bugs/18_hang_on_line_comments_at_eof index 957ed47..957ed47 100644 --- a/tests/custom/03_bugs/18_hang_on_line_comments_at_eof +++ b/tests/custom/04_bugs/18_hang_on_line_comments_at_eof diff --git a/tests/custom/03_bugs/19_truncated_format_string b/tests/custom/04_bugs/19_truncated_format_string index 8ddd0a3..8ddd0a3 100644 --- a/tests/custom/03_bugs/19_truncated_format_string +++ b/tests/custom/04_bugs/19_truncated_format_string diff --git a/tests/custom/03_bugs/20_use_strict_stack_mismatch b/tests/custom/04_bugs/20_use_strict_stack_mismatch index 7294d23..7294d23 100644 --- a/tests/custom/03_bugs/20_use_strict_stack_mismatch +++ b/tests/custom/04_bugs/20_use_strict_stack_mismatch diff --git a/tests/custom/03_bugs/21_compiler_parenthesized_prop_keyword b/tests/custom/04_bugs/21_compiler_parenthesized_prop_keyword index 472b2af..472b2af 100644 --- a/tests/custom/03_bugs/21_compiler_parenthesized_prop_keyword +++ b/tests/custom/04_bugs/21_compiler_parenthesized_prop_keyword diff --git a/tests/custom/03_bugs/22_compiler_break_continue_scoping b/tests/custom/04_bugs/22_compiler_break_continue_scoping index 461b144..461b144 100644 --- a/tests/custom/03_bugs/22_compiler_break_continue_scoping +++ b/tests/custom/04_bugs/22_compiler_break_continue_scoping diff --git a/tests/custom/03_bugs/23_compiler_parenthesized_division b/tests/custom/04_bugs/23_compiler_parenthesized_division index a70703f..a70703f 100644 --- a/tests/custom/03_bugs/23_compiler_parenthesized_division +++ b/tests/custom/04_bugs/23_compiler_parenthesized_division diff --git a/tests/custom/03_bugs/24_compiler_local_for_loop_declaration b/tests/custom/04_bugs/24_compiler_local_for_loop_declaration index aafde55..aafde55 100644 --- a/tests/custom/03_bugs/24_compiler_local_for_loop_declaration +++ b/tests/custom/04_bugs/24_compiler_local_for_loop_declaration diff --git a/tests/custom/03_bugs/25_lexer_shifted_offsets b/tests/custom/04_bugs/25_lexer_shifted_offsets index db10121..db10121 100644 --- a/tests/custom/03_bugs/25_lexer_shifted_offsets +++ b/tests/custom/04_bugs/25_lexer_shifted_offsets diff --git a/tests/custom/03_bugs/26_compiler_jmp_to_zero b/tests/custom/04_bugs/26_compiler_jmp_to_zero index e7e0127..e7e0127 100644 --- a/tests/custom/03_bugs/26_compiler_jmp_to_zero +++ b/tests/custom/04_bugs/26_compiler_jmp_to_zero diff --git a/tests/custom/03_bugs/26_invalid_sparse_array_set b/tests/custom/04_bugs/27_invalid_sparse_array_set index 4c47039..4c47039 100644 --- a/tests/custom/03_bugs/26_invalid_sparse_array_set +++ b/tests/custom/04_bugs/27_invalid_sparse_array_set diff --git a/tests/custom/04_bugs/28_null_equality b/tests/custom/04_bugs/28_null_equality new file mode 100644 index 0000000..b71a3b1 --- /dev/null +++ b/tests/custom/04_bugs/28_null_equality @@ -0,0 +1,31 @@ +When comparing `null` with another value for loose equality or inequality, +the values `0`, `0.0`, `false` and `"0x0"` (any string interpreted as +numeric null) were incorrectly treated as equal. + +-- Testcase -- +{{ null == 0 }} +{{ null == 0.0 }} +{{ null == false }} +{{ null == "0x0" }} +{{ null == null }} + +{{ null != 0 }} +{{ null != 0.0 }} +{{ null != false }} +{{ null != "0x0" }} +{{ null != null }} +-- End -- + +-- Expect stdout -- +false +false +false +false +true + +true +true +true +true +false +-- End -- diff --git a/tests/custom/04_bugs/29_empty_string_as_number b/tests/custom/04_bugs/29_empty_string_as_number new file mode 100644 index 0000000..675f8a1 --- /dev/null +++ b/tests/custom/04_bugs/29_empty_string_as_number @@ -0,0 +1,17 @@ +When an empty string was casted to a number, e.g. explicitly through `+` +or `int()` or implicitly through numerical calculations, it was incorrectly +treated as `NaN` and not `0`. + +-- Testcase -- +{{ +"" }} +{{ int("") }} +{{ "" + 0 }} +{{ "" - 0.0 }} +-- End -- + +-- Expect stdout -- +0 +0 +0 +0 +-- End -- diff --git a/tests/custom/run_tests.sh b/tests/custom/run_tests.sh index 6869776..d09859c 100755 --- a/tests/custom/run_tests.sh +++ b/tests/custom/run_tests.sh @@ -21,6 +21,12 @@ extract_sections() { outfile=$(printf "%s/%03d.args" "$dir" $count) printf "" > "$outfile" ;; + "-- Vars --") + tag="vars" + count=$((count + 1)) + outfile=$(printf "%s/%03d.vars" "$dir" $count) + printf "" > "$outfile" + ;; "-- Testcase --") tag="test" count=$((count + 1)) @@ -62,15 +68,28 @@ run_testcase() { local err=$5 local code=$6 local args=$7 + local vars=$8 local fail=0 ( cd "$topdir" + + IFS=$'\n' + + local var + for var in $vars; do + case "$var" in + *=*) export "$var" ;; + esac + done + + IFS=$' \t\n' + $ucode_bin $args -e '{ "REQUIRE_SEARCH_PATH": [ "'"$ucode_lib"'/*.so" ] }' -i - <"$in" >"$dir/res.out" 2>"$dir/res.err" ) - touch "$dir/empty" printf "%d\n" $? > "$dir/res.code" + touch "$dir/empty" if ! cmp -s "$dir/res.err" "${err:-$dir/empty}"; then [ $fail = 0 ] && printf "!\n" @@ -122,21 +141,23 @@ run_test() { if [ $testcase_first = 1 ]; then # Flush previous test if [ -n "$ein" ]; then - run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) eout="" eerr="" ecode="" eargs="" + evars="" fi ein=$res else - run_testcase $count "/tmp/test.$$" "$res" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$res" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) eout="" eerr="" ecode="" eargs="" + evars="" fi ;; @@ -144,12 +165,13 @@ run_test() { *.stderr) eerr=$res ;; *.exitcode) ecode=$res ;; *.args) eargs=$(cat "$res") ;; + *.vars) evars=$(cat "$res") ;; esac done # Flush last test if [ $testcase_first = 1 ] && [ -n "$eout$eerr$ecode" ]; then - run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" || failed=$((failed + 1)) + run_testcase $count "/tmp/test.$$" "$ein" "$eout" "$eerr" "$ecode" "$eargs" "$evars" || failed=$((failed + 1)) fi rm -r "/tmp/test.$$" @@ -1918,8 +1918,13 @@ ucv_compare(int how, uc_value_t *v1, uc_value_t *v2, int *deltap) double d1, d2; int8_t delta; - /* if both operands are strings, compare bytewise */ - if (t1 == UC_STRING && t2 == UC_STRING) { + /* at least one operand is null and we compare for equality or inequality ... */ + if ((!v1 || !v2) && (how == I_EQ || how == I_NE)) { + delta = (v1 != v2); + } + + /* ... otherwise if both operands are strings, compare bytewise ... */ + else if (t1 == UC_STRING && t2 == UC_STRING) { delta = strcmp(ucv_string_get(v1), ucv_string_get(v2)); } @@ -62,7 +62,7 @@ uc_number_parse(const char *buf, char **end) p++; } - if (!isxdigit(*p)) + if (*p != 0 && !isxdigit(*p)) return NULL; if (!end) @@ -73,7 +73,7 @@ uc_number_parse(const char *buf, char **end) if (**end == '.' || **end == 'e' || **end == 'E') { d = strtod(p, end); - if (*end == p || (!isspace(**end) && **end != 0)) + if (!isspace(**end) && **end != 0) return NULL; if (neg) @@ -82,7 +82,7 @@ uc_number_parse(const char *buf, char **end) return ucv_double_new(d); } - if (*end == p || (!isspace(**end) && **end != 0)) + if (!isspace(**end) && **end != 0) return NULL; if (neg) { |