From 1bd1a36a8125f8c66cc59f686bd0ad5611eac3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Csaba=20Osztrogon=C3=A1c?= Date: Mon, 30 Mar 2020 12:26:56 +0200 Subject: [PATCH] Bump reference platform to Ubuntu 18.04 LTS (#3037) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ubuntu 14.04 reached its end of life on April 30m 2019. Let's bump the reference to the latest LTS, which is 18.04. Ubuntu 18.04 has newer Pylint and Cppcheck, the necessary fixes and suppresses are also included in this PR. JerryScript-DCO-1.0-Signed-off-by: Csaba Osztrogonác oszi@inf.u-szeged.hu --- .travis.yml | 13 +++++-------- docs/00.GETTING-STARTED.md | 2 +- jerry-core/ecma/base/ecma-helpers-number.c | 4 ++-- jerry-core/ecma/base/ecma-helpers-value.c | 1 + jerry-core/ecma/builtin-objects/ecma-builtins.c | 1 + .../ecma/operations/ecma-function-object.c | 2 ++ jerry-core/jmem/jmem-heap.c | 1 + jerry-debugger/jerry_client.py | 2 +- jerry-debugger/jerry_client_main.py | 4 ++-- jerry-ext/handler/handler-register.c | 17 +++++++++++++---- jerry-libm/acos.c | 2 +- jerry-libm/asin.c | 2 +- jerry-libm/atan2.c | 2 +- jerry-libm/exp.c | 2 +- jerry-libm/fmod.c | 6 +++--- jerry-libm/pow.c | 4 ++-- jerry-libm/sqrt.c | 2 +- jerry-main/cli.c | 2 +- jerry-main/main-unix-snapshot.c | 10 +++++----- jerry-main/main-unix.c | 6 ++++++ tests/unit-core/test-arraybuffer.c | 1 + tests/unit-core/test-typedarray.c | 4 ++-- tools/check-cppcheck.sh | 1 + tools/cppcheck/suppressions-list | 7 ++++++- tools/run-tests.py | 2 +- 25 files changed, 62 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4820c0735..acf913095 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: c -# Default environment: Ubuntu Trusty 14.04. +# Default environment: Ubuntu Bionic 18.04. os: linux -dist: trusty +dist: bionic # Default job task: run tests as defined in the $OPT environment variable. # Jobs can redefine the 'script' stage in the matrix below. @@ -12,13 +12,12 @@ script: tools/run-tests.py $OPTS matrix: include: - name: "Checks" - install: pip install --user pylint==1.6.5 script: - tools/run-tests.py --check-signed-off=travis --check-doxygen --check-vera --check-license --check-magic-strings --check-pylint - travis_wait 40 tools/run-tests.py --check-cppcheck addons: apt: - packages: [doxygen, cppcheck, vera++] + packages: [doxygen, cppcheck, vera++, pylint] - name: "Linux/x86-64 Build, Correctness & Debugger Tests" env: @@ -70,22 +69,20 @@ matrix: - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js --buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold" - ASAN_OPTIONS=detect_stack_use_after_return=1:check_initialization_order=true:strict_init_order=true - TIMEOUT=600 - compiler: gcc-5 addons: apt: sources: ubuntu-toolchain-r-test - packages: [gcc-5, gcc-5-multilib] + packages: [gcc-multilib] - name: "UBSAN Tests" env: - OPTS="--quiet --jerry-tests --jerry-test-suite --skip-list=parser-oom.js,parser-oom2.js --buildoptions=--compile-flag=-fsanitize=undefined,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold" - UBSAN_OPTIONS=print_stacktrace=1 - TIMEOUT=600 - compiler: gcc-5 addons: apt: sources: ubuntu-toolchain-r-test - packages: [gcc-5, gcc-5-multilib] + packages: [gcc-multilib] - name: "Coverity Scan & SonarQube" env: diff --git a/docs/00.GETTING-STARTED.md b/docs/00.GETTING-STARTED.md index d16d9b894..9ef07a4a8 100644 --- a/docs/00.GETTING-STARTED.md +++ b/docs/00.GETTING-STARTED.md @@ -1,6 +1,6 @@ ## Setting up prerequisites -Currently, only Ubuntu 14.04+ is officially supported as primary development environment. +Currently, only Ubuntu 18.04+ is officially supported as primary development environment. There are several dependencies, that should be installed manually. The following list is the absolute minimum for building: diff --git a/jerry-core/ecma/base/ecma-helpers-number.c b/jerry-core/ecma/base/ecma-helpers-number.c index 8de473d65..6f48f9fee 100644 --- a/jerry-core/ecma/base/ecma-helpers-number.c +++ b/jerry-core/ecma/base/ecma-helpers-number.c @@ -697,7 +697,7 @@ ecma_number_parse_int (const lit_utf8_byte_t *string_buff, /**< routine's first * string buffer's size */ ecma_value_t radix) /**< routine's second argument */ { - if (string_buff_size <= 0) + if (string_buff_size == 0) { return ecma_make_nan_value (); } @@ -874,7 +874,7 @@ ecma_number_parse_float (const lit_utf8_byte_t *string_buff, /**< routine's firs lit_utf8_size_t string_buff_size) /**< routine's first argument's * string buffer's size */ { - if (string_buff_size <= 0) + if (string_buff_size == 0) { return ecma_make_nan_value (); } diff --git a/jerry-core/ecma/base/ecma-helpers-value.c b/jerry-core/ecma/base/ecma-helpers-value.c index 0ef1731b5..cc2354a4e 100644 --- a/jerry-core/ecma/base/ecma-helpers-value.c +++ b/jerry-core/ecma/base/ecma-helpers-value.c @@ -40,6 +40,7 @@ JERRY_STATIC_ASSERT (sizeof (jmem_cpointer_t) <= sizeof (jmem_cpointer_tag_t), #ifdef ECMA_VALUE_CAN_STORE_UINTPTR_VALUE_DIRECTLY +/* cppcheck-suppress zerodiv */ JERRY_STATIC_ASSERT (sizeof (uintptr_t) <= sizeof (ecma_value_t), uintptr_t_must_fit_in_ecma_value_t); diff --git a/jerry-core/ecma/builtin-objects/ecma-builtins.c b/jerry-core/ecma/builtin-objects/ecma-builtins.c index 5db3e96d4..6deb99799 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtins.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtins.c @@ -349,6 +349,7 @@ ecma_instantiate_builtin (ecma_builtin_id_t obj_builtin_id) /**< built-in id */ ecma_object_t *prototype_obj_p; + /* cppcheck-suppress arrayIndexOutOfBoundsCond */ if (JERRY_UNLIKELY (object_prototype_builtin_id == ECMA_BUILTIN_ID__COUNT)) { prototype_obj_p = NULL; diff --git a/jerry-core/ecma/operations/ecma-function-object.c b/jerry-core/ecma/operations/ecma-function-object.c index 7f7ccbd72..456948ea0 100644 --- a/jerry-core/ecma/operations/ecma-function-object.c +++ b/jerry-core/ecma/operations/ecma-function-object.c @@ -1296,7 +1296,9 @@ ecma_op_lazy_instantiate_prototype_object (ecma_object_t *object_p) /**< the fun } #endif /* ENABLED (JERRY_ES2015) */ +#if ENABLED (JERRY_ES2015) if (proto_object_p == NULL) +#endif /* ENABLED (JERRY_ES2015) */ { proto_object_p = ecma_op_create_object_object_noarg (); } diff --git a/jerry-core/jmem/jmem-heap.c b/jerry-core/jmem/jmem-heap.c index 63d331adb..0f504ea2b 100644 --- a/jerry-core/jmem/jmem-heap.c +++ b/jerry-core/jmem/jmem-heap.c @@ -288,6 +288,7 @@ jmem_heap_gc_and_alloc_block (const size_t size, /**< required memory size */ void *data_space_p = jmem_heap_alloc (size); + /* cppcheck-suppress memleak */ while (JERRY_UNLIKELY (data_space_p == NULL) && JERRY_LIKELY (pressure < max_pressure)) { pressure++; diff --git a/jerry-debugger/jerry_client.py b/jerry-debugger/jerry_client.py index 4faf6d963..d1cbe28b6 100755 --- a/jerry-debugger/jerry_client.py +++ b/jerry-debugger/jerry_client.py @@ -252,7 +252,7 @@ def src_check_args(args): print("Error: Non-negative integer number expected: %s" % (val_errno)) return -1 -# pylint: disable=too-many-branches,too-many-locals,too-many-statements,redefined-variable-type +# pylint: disable=too-many-branches,too-many-locals,too-many-statements def main(): args = jerry_client_main.arguments_parse() diff --git a/jerry-debugger/jerry_client_main.py b/jerry-debugger/jerry_client_main.py index 8e111013d..eeea93d21 100644 --- a/jerry-debugger/jerry_client_main.py +++ b/jerry-debugger/jerry_client_main.py @@ -267,7 +267,7 @@ class DebuggerAction(object): class JerryDebugger(object): - # pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use,redefined-variable-type + # pylint: disable=too-many-instance-attributes,too-many-statements,too-many-public-methods,no-self-use def __init__(self, channel): self.prompt = False self.function_list = {} @@ -490,7 +490,7 @@ class JerryDebugger(object): index = int(args) if index < 0: print ("Error: A non negative integer number expected") - return + return "" except ValueError as val_errno: return "Error: Non negative integer number expected, %s\n" % (val_errno) diff --git a/jerry-ext/handler/handler-register.c b/jerry-ext/handler/handler-register.c index ad35d8c33..d808061f6 100644 --- a/jerry-ext/handler/handler-register.c +++ b/jerry-ext/handler/handler-register.c @@ -63,7 +63,13 @@ jerryx_set_properties (const jerry_value_t target_object, /**< target object */ { #define JERRYX_SET_PROPERTIES_RESULT(VALUE, IDX) ((jerryx_register_result) { VALUE, IDX }) uint32_t idx = 0; - for (; ((entries + idx) != NULL) && (entries[idx].name != NULL); idx++) + + if (entries == NULL) + { + return JERRYX_SET_PROPERTIES_RESULT (jerry_create_undefined (), 0); + } + + for (; (entries[idx].name != NULL); idx++) { const jerryx_property_entry *entry = &entries[idx]; @@ -99,9 +105,12 @@ void jerryx_release_property_entry (const jerryx_property_entry entries[], /**< list of property entries */ const jerryx_register_result register_result) /**< previous result of registration */ { - for (uint32_t idx = register_result.registered; - ((entries + idx) != NULL) && (entries[idx].name != NULL); - idx++) + if (entries == NULL) + { + return; + } + + for (uint32_t idx = register_result.registered; entries[idx].name != NULL; idx++) { jerry_release_value (entries[idx].value); } diff --git a/jerry-libm/acos.c b/jerry-libm/acos.c index 875d41ef5..14e6ded4b 100644 --- a/jerry-libm/acos.c +++ b/jerry-libm/acos.c @@ -88,7 +88,7 @@ acos (double x) return pi + 2.0 * pio2_lo; } } - return (x - x) / (x - x); /* acos(|x|>1) is NaN */ + return NAN; /* acos(|x|>1) is NaN */ } if (ix < 0x3fe00000) /* |x| < 0.5 */ { diff --git a/jerry-libm/asin.c b/jerry-libm/asin.c index 1af9c3c52..2c70db522 100644 --- a/jerry-libm/asin.c +++ b/jerry-libm/asin.c @@ -89,7 +89,7 @@ asin (double x) { return x * pio2_hi + x * pio2_lo; } - return (x - x) / (x - x); /* asin(|x|>1) is NaN */ + return NAN; /* asin(|x|>1) is NaN */ } else if (ix < 0x3fe00000) /* |x| < 0.5 */ { diff --git a/jerry-libm/atan2.c b/jerry-libm/atan2.c index 025e128f0..5f9eb1373 100644 --- a/jerry-libm/atan2.c +++ b/jerry-libm/atan2.c @@ -82,7 +82,7 @@ atan2 (double y, double x) { return atan (y); } - m = ((hy >> 31) & 1) | ((hx >> 30) & 2); /* 2 * sign(x) + sign(y) */ + m = ((hy < 0) ? 1 : 0) + ((hx < 0) ? 2 : 0); /* 2 * sign(x) + sign(y) */ /* when y = 0 */ if ((iy | ly) == 0) diff --git a/jerry-libm/exp.c b/jerry-libm/exp.c index 8970528fc..201dd02d8 100644 --- a/jerry-libm/exp.c +++ b/jerry-libm/exp.c @@ -197,7 +197,7 @@ exp (double x) /* default IEEE double exp */ } if (k >= -1021) { - ret.as_int.hi += (k << 20); /* add k to y's exponent */ + ret.as_int.hi += (((unsigned int) k) << 20); /* add k to y's exponent */ return ret.dbl; } else diff --git a/jerry-libm/fmod.c b/jerry-libm/fmod.c index 7a74bf3f6..0c335e450 100644 --- a/jerry-libm/fmod.c +++ b/jerry-libm/fmod.c @@ -53,7 +53,7 @@ fmod (double x, double y) if ((hy | ly) == 0 || (hx >= 0x7ff00000) || /* y = 0, or x not finite */ ((hy | ((ly | -ly) >> 31)) > 0x7ff00000)) /* or y is NaN */ { - return (x * y) / (x * y); + return NAN; } if (hx <= hy) { @@ -123,7 +123,7 @@ fmod (double x, double y) n = -1022 - ix; if (n <= 31) { - hx = (hx << n) | (lx >> (32 - n)); + hx = (((unsigned int) hx) << n) | (lx >> (32 - n)); lx <<= n; } else @@ -141,7 +141,7 @@ fmod (double x, double y) n = -1022 - iy; if (n <= 31) { - hy = (hy << n) | (ly >> (32 - n)); + hy = (((unsigned int) hy) << n) | (ly >> (32 - n)); ly <<= n; } else diff --git a/jerry-libm/pow.c b/jerry-libm/pow.c index 581876c1d..a33b9b8f7 100644 --- a/jerry-libm/pow.c +++ b/jerry-libm/pow.c @@ -254,12 +254,12 @@ pow (double x, double y) } } - n = (hx >> 31) + 1; + n = (hx < 0) ? 0 : 1; /* (x<0)**(non-int) is NaN */ if ((n | yisint) == 0) { - return (x - x) / (x - x); + return NAN; } s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ diff --git a/jerry-libm/sqrt.c b/jerry-libm/sqrt.c index 182a76ff9..cdd548871 100644 --- a/jerry-libm/sqrt.c +++ b/jerry-libm/sqrt.c @@ -125,7 +125,7 @@ sqrt (double x) } else if (ix0 < 0) /* sqrt(-ve) = sNaN */ { - return (x - x) / (x - x); + return NAN; } } /* normalize x */ diff --git a/jerry-main/cli.c b/jerry-main/cli.c index 9fbc7a9c0..1f14ed867 100644 --- a/jerry-main/cli.c +++ b/jerry-main/cli.c @@ -112,7 +112,7 @@ cli_consume_option (cli_state_t *state_p) /**< state of the command line option state_p->arg = arg; - if (arg[0] != '-' || (arg[0] == '-' && arg[1] == '\0')) + if (arg[0] != '-' || arg[1] == '\0') { return CLI_OPT_DEFAULT; } diff --git a/jerry-main/main-unix-snapshot.c b/jerry-main/main-unix-snapshot.c index 244f7ee62..36c3754b0 100644 --- a/jerry-main/main-unix-snapshot.c +++ b/jerry-main/main-unix-snapshot.c @@ -150,7 +150,7 @@ read_file (uint8_t *input_pos_p, /**< next position in the input buffer */ return 0; } - printf ("Input file '%s' (%lu bytes) loaded.\n", file_name, bytes_read); + printf ("Input file '%s' (%zu bytes) loaded.\n", file_name, bytes_read); return bytes_read; } /* read_file */ @@ -426,7 +426,7 @@ process_generate (cli_state_t *cli_state_p, /**< cli state */ fwrite (output_buffer, sizeof (uint8_t), snapshot_size, snapshot_file_p); fclose (snapshot_file_p); - printf ("Created snapshot file: '%s' (%lu bytes)\n", output_file_name_p, (unsigned long) snapshot_size); + printf ("Created snapshot file: '%s' (%zu bytes)\n", output_file_name_p, snapshot_size); jerry_cleanup (); return JERRY_STANDALONE_EXIT_CODE_OK; @@ -584,7 +584,7 @@ process_literal_dump (cli_state_t *cli_state_p, /**< cli state */ return JERRY_STANDALONE_EXIT_CODE_FAIL; } - printf ("Successfully merged the input snapshots (%lu bytes).\n", merged_snapshot_size); + printf ("Successfully merged the input snapshots (%zu bytes).\n", merged_snapshot_size); lit_buf_sz = jerry_get_literals_from_snapshot (output_buffer, merged_snapshot_size, @@ -618,7 +618,7 @@ process_literal_dump (cli_state_t *cli_state_p, /**< cli state */ fwrite (literal_buffer, sizeof (uint8_t), lit_buf_sz, file_p); fclose (file_p); - printf ("Literals are saved into '%s' (%lu bytes).\n", literals_file_name_p, lit_buf_sz); + printf ("Literals are saved into '%s' (%zu bytes).\n", literals_file_name_p, lit_buf_sz); jerry_cleanup (); return JERRY_STANDALONE_EXIT_CODE_OK; @@ -752,7 +752,7 @@ process_merge (cli_state_t *cli_state_p, /**< cli state */ fwrite (output_buffer, 1u, merged_snapshot_size, file_p); fclose (file_p); - printf ("Merge is completed. Merged snapshot is saved into '%s' (%lu bytes).\n", + printf ("Merge is completed. Merged snapshot is saved into '%s' (%zu bytes).\n", output_file_name_p, merged_snapshot_size); diff --git a/jerry-main/main-unix.c b/jerry-main/main-unix.c index 913349ea5..367f50964 100644 --- a/jerry-main/main-unix.c +++ b/jerry-main/main-unix.c @@ -53,6 +53,12 @@ static const uint32_t * read_file (const char *file_name, size_t *out_size_p) { + if (file_name == NULL) + { + jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Error: failed to open file, missing filename\n"); + return NULL; + } + FILE *file; if (!strcmp ("-", file_name)) { diff --git a/tests/unit-core/test-arraybuffer.c b/tests/unit-core/test-arraybuffer.c index c4f944aeb..403dc6186 100644 --- a/tests/unit-core/test-arraybuffer.c +++ b/tests/unit-core/test-arraybuffer.c @@ -304,6 +304,7 @@ main (void) /* Test ArrayBuffer external memory map/unmap */ { const uint32_t buffer_size = 20; + /* cppcheck-suppress variableScope */ JERRY_VLA (uint8_t, buffer_p, buffer_size); { jerry_value_t input_buffer = jerry_create_arraybuffer_external (buffer_size, buffer_p, NULL); diff --git a/tests/unit-core/test-typedarray.c b/tests/unit-core/test-typedarray.c index 31e0d145d..2b34eb51e 100644 --- a/tests/unit-core/test-typedarray.c +++ b/tests/unit-core/test-typedarray.c @@ -155,7 +155,7 @@ test_typedarray_queries (test_entry_t test_entries[]) /**< test cases */ */ static void test_buffer_value (uint64_t value, /**< value to test for */ - const uint8_t *buffer, /**< buffer to read value from */ + const void *buffer, /**< buffer to read value from */ uint32_t start_offset, /**< start offset of the value */ jerry_typedarray_type_t typedarray_type, /**< type of TypedArray */ uint32_t bytes_per_element) /**< bytes per element for the given type */ @@ -518,11 +518,11 @@ main (void) /* Test TypedArray operations in js */ { const uint32_t element_count = 14; - uint8_t expected_value = 42; jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT8, element_count); { + uint8_t expected_value = 42; JERRY_VLA (uint8_t, expected_data, element_count); memset (expected_data, expected_value, element_count); diff --git a/tools/check-cppcheck.sh b/tools/check-cppcheck.sh index 8da40d501..2f95d1ba7 100755 --- a/tools/check-cppcheck.sh +++ b/tools/check-cppcheck.sh @@ -40,6 +40,7 @@ cppcheck -j$CPPCHECK_JOBS --force \ --enable=warning,style,performance,portability,information \ --template="{file}:{line}: {severity}({id}): {message}" \ --error-exitcode=1 \ + --inline-suppr \ --exitcode-suppressions=tools/cppcheck/suppressions-list \ --suppressions-list=tools/cppcheck/suppressions-list \ "${INCLUDE_DIRS[@]}" \ diff --git a/tools/cppcheck/suppressions-list b/tools/cppcheck/suppressions-list index ea48aec21..d2277a83d 100644 --- a/tools/cppcheck/suppressions-list +++ b/tools/cppcheck/suppressions-list @@ -1,4 +1,9 @@ wrongmathcall:tests/unit-libm/test-libm.inc.h variableScope:jerry-libm/*.c invalidPointerCast:jerry-libm/*.c -commaSeparatedReturn:* + +ConfigurationNotChecked:jerry-core/ecma/builtin-objects/ecma-builtin-global.inc.h +ConfigurationNotChecked:jerry-core/ecma/builtin-objects/ecma-builtin-helpers-macro-defines.inc.h +ConfigurationNotChecked:jerry-core/ecma/builtin-objects/ecma-builtin-function-prototype.inc.h +ConfigurationNotChecked:jerry-core/ecma/builtin-objects/ecma-builtin-object.inc.h +ConfigurationNotChecked:jerry-core/ecma/builtin-objects/ecma-builtin-helpers-macro-undefs.inc.h diff --git a/tools/run-tests.py b/tools/run-tests.py index fedabf2c3..88605912f 100755 --- a/tools/run-tests.py +++ b/tools/run-tests.py @@ -301,7 +301,7 @@ def hash_binary(bin_path): hasher = hashlib.sha1() with open(bin_path, 'rb') as bin_file: buf = bin_file.read(blocksize) - while len(buf) > 0: + while buf: hasher.update(buf) buf = bin_file.read(blocksize) return hasher.hexdigest()