Skip to content

Commit

Permalink
Update cppcheck
Browse files Browse the repository at this point in the history
Re-enable cppcheck CI job

Update cppcheck suppression list:
    The new version of cppcheck raises warnings for many potential
    issues that are guarded against, so those warnings have been
    supressed.

Handle realloc failures:
    - jerry-ext/util/sources.c
    - jerry-port/common/jerry-port-io.c

JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu
  • Loading branch information
matetokodi committed Nov 14, 2023
1 parent 5562ab9 commit d4c6a42
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
python-version: '3.10'
- run: sudo apt update
# TODO: update checkers to current versions available in ubuntu 22.04
# - run: sudo apt install clang-format-10 cppcheck python-serial
- run: sudo apt install pylint doxygen
# - run: sudo apt install clang-format-10 python-serial
- run: sudo apt install pylint doxygen cppcheck
- run: $RUNNER --check-signed-off=gh-actions
if: ${{ always() }}
- run: $RUNNER --check-doxygen
Expand All @@ -31,8 +31,8 @@ jobs:
# if: ${{ always() }}
- run: $RUNNER --check-pylint
if: ${{ always() }}
# - run: $RUNNER --check-cppcheck
# if: ${{ always() }}
- run: $RUNNER --check-cppcheck
if: ${{ always() }}

Linux_x86-64_Build_Correctness_Debugger_Tests:
runs-on: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions jerry-core/ecma/base/ecma-helpers-errol.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,24 @@ ecma_errol0_dtoa (double val, /**< ecma number */
int32_t *exp_p) /**< [out] exponent */
{
double power_of_10 = 1.0;
int32_t exp = 1;
int32_t exponent = 1;

/* normalize the midpoint */
ecma_high_prec_t mid;

mid.value = val;
mid.offset = 0.0;

while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exp < 308))
while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exponent < 308))
{
exp++;
exponent++;
ecma_divide_high_prec_by_10 (&mid);
power_of_10 /= 10.0;
}

while (((mid.value < 1.0) || ((mid.value == 1.0) && (mid.offset < 0.0))) && (exp > -307))
while (((mid.value < 1.0) || ((mid.value == 1.0) && (mid.offset < 0.0))) && (exponent > -307))
{
exp--;
exponent--;
ecma_multiply_high_prec_by_10 (&mid);
power_of_10 *= 10.0;
}
Expand All @@ -185,14 +185,14 @@ ecma_errol0_dtoa (double val, /**< ecma number */

while (high_bound.value > 10.0 || (high_bound.value == 10.0 && (high_bound.offset >= 0.0)))
{
exp++;
exponent++;
ecma_divide_high_prec_by_10 (&high_bound);
ecma_divide_high_prec_by_10 (&low_bound);
}

while (high_bound.value < 1.0 || (high_bound.value == 1.0 && (high_bound.offset < 0.0)))
{
exp--;
exponent--;
ecma_multiply_high_prec_by_10 (&high_bound);
ecma_multiply_high_prec_by_10 (&low_bound);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ ecma_errol0_dtoa (double val, /**< ecma number */
double mdig = (high_bound.value + low_bound.value) / 2.0 + 0.5;
*dst_p++ = (lit_utf8_byte_t) ('0' + (uint8_t) mdig);

*exp_p = exp;
*exp_p = exponent;

return (lit_utf8_size_t) (dst_p - buffer_p);
} /* ecma_errol0_dtoa */
Expand Down
3 changes: 0 additions & 3 deletions jerry-ext/handle-scope/handle-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
* Escape handle to parent scope
*/
*result = jerryx_handle_scope_add_handle_to (found_handle, parent);
}

if (should_promote)
{
scope->escaped = true;
}
return jerryx_handle_scope_ok;
Expand Down
6 changes: 5 additions & 1 deletion jerry-ext/util/sources.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ jerryx_source_exec_stdin (void)
}

jerry_size_t new_size = source_size + line_size;
source_p = realloc (source_p, new_size);
jerry_char_t *tmp = realloc (source_p, new_size);
if (tmp == NULL) {
return jerry_throw_sz(JERRY_ERROR_COMMON, "Out of memory.");
}
source_p = tmp;

memcpy (source_p + source_size, line_p, line_size);
jerry_port_line_free (line_p);
Expand Down
7 changes: 6 additions & 1 deletion jerry-port/common/jerry-port-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ jerry_port_line_read (jerry_size_t *out_size_p)
while (true)
{
allocated += 64;
line_p = realloc (line_p, allocated);
char *tmp = realloc (line_p, allocated);
if (tmp == NULL)
{
jerry_port_fatal (JERRY_FATAL_OUT_OF_MEMORY);
}
line_p = tmp;

while (bytes < allocated - 1)
{
Expand Down
12 changes: 6 additions & 6 deletions tests/unit-core/test-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ main (void)
if (jerry_feature_enabled (JERRY_FEATURE_PROXY))
{
jerry_value_t target = jerry_object ();
jerry_value_t handler = jerry_object ();
jerry_value_t proxy = jerry_proxy (target, handler);
jerry_value_t handler_ = jerry_object ();
jerry_value_t proxy = jerry_proxy (target, handler_);
jerry_value_t obj_proto = jerry_eval ((jerry_char_t *) "Object.prototype", 16, JERRY_PARSE_NO_OPTS);

jerry_value_free (target);
jerry_value_free (handler);
jerry_value_free (handler_);
proto_val = jerry_object_proto (proxy);
TEST_ASSERT (!jerry_value_is_exception (proto_val));
TEST_ASSERT (proto_val == obj_proto);
Expand Down Expand Up @@ -745,8 +745,8 @@ main (void)
if (jerry_feature_enabled (JERRY_FEATURE_PROXY))
{
jerry_value_t target = jerry_object ();
jerry_value_t handler = jerry_object ();
jerry_value_t proxy = jerry_proxy (target, handler);
jerry_value_t handler_ = jerry_object ();
jerry_value_t proxy = jerry_proxy (target, handler_);
new_proto = jerry_eval ((jerry_char_t *) "Function.prototype", 18, JERRY_PARSE_NO_OPTS);

res = jerry_object_set_proto (proxy, new_proto);
Expand All @@ -755,7 +755,7 @@ main (void)
TEST_ASSERT (target_proto == new_proto);

jerry_value_free (target);
jerry_value_free (handler);
jerry_value_free (handler_);
jerry_value_free (proxy);
jerry_value_free (new_proto);
jerry_value_free (target_proto);
Expand Down
9 changes: 3 additions & 6 deletions tests/unit-core/test-snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,8 @@ main (void)
jerry_cleanup ();

test_exec_snapshot (snapshot_buffer, snapshot_size, JERRY_SNAPSHOT_EXEC_ALLOW_STATIC);
}

/* Merge snapshot */
if (jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_SAVE) && jerry_feature_enabled (JERRY_FEATURE_SNAPSHOT_EXEC))
{
/* Merge snapshot */
static uint32_t snapshot_buffer_0[SNAPSHOT_BUFFER_SIZE];
static uint32_t snapshot_buffer_1[SNAPSHOT_BUFFER_SIZE];
size_t snapshot_sizes[2];
Expand All @@ -298,10 +295,10 @@ main (void)

jerry_init (JERRY_INIT_EMPTY);

jerry_value_t parse_result = jerry_parse (code_to_snapshot1, sizeof (code_to_snapshot1) - 1, NULL);
parse_result = jerry_parse (code_to_snapshot1, sizeof (code_to_snapshot1) - 1, NULL);
TEST_ASSERT (!jerry_value_is_exception (parse_result));

jerry_value_t generate_result = jerry_generate_snapshot (parse_result, 0, snapshot_buffer_0, SNAPSHOT_BUFFER_SIZE);
generate_result = jerry_generate_snapshot (parse_result, 0, snapshot_buffer_0, SNAPSHOT_BUFFER_SIZE);
jerry_value_free (parse_result);

TEST_ASSERT (!jerry_value_is_exception (generate_result) && jerry_value_is_number (generate_result));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit-core/test-to-integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ main (void)
TEST_ASSERT (num == ecma_number_make_infinity (false));

/* 5 */
ecma_value_t floor = ecma_make_number_value (3.001f);
ecma_value_t floor_val = ecma_make_number_value (3.001f);

result = ecma_op_to_integer (floor, &num);
result = ecma_op_to_integer (floor_val, &num);

ecma_free_value (floor);
ecma_free_value (floor_val);

TEST_ASSERT (!ECMA_IS_VALUE_ERROR (result));
TEST_ASSERT (num == 3);
Expand Down
47 changes: 43 additions & 4 deletions tools/cppcheck/suppressions-list
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
wrongmathcall:tests/unit-math/test-math.inc.h
variableScope:jerry-math/*.c
invalidPointerCast:jerry-math/*.c

ConfigurationNotChecked:jerry-core/*.inc.h
arrayIndexOutOfBoundsCond:jerry-core/*.c
autoVariables:jerry-core/*.c
constParameter:jerry-core/*.c
constParameter:jerry-ext/*.c
constParameter:jerry-math/*.c
constParameter:tests/unit-core/*.c
duplicateValueTernary:jerry-core/*.c
incorrectStringBooleanError:tests/unit-core/test-newtarget.c
integerOverflowCond:jerry-math/*.c
invalidFunctionArg:tests/unit-math/test-math.inc.h
invalidPointerCast:jerry-math/*.c
knownConditionTrueFalse:jerry-core/*.c
knownConditionTrueFalse:jerry-math/*.c
negativeIndex:jerry-core/*.c
nullPointerArithmetic:jerry-core/parser/js/js-parser-line-info-create.c:572
nullPointerArithmetic:jerry-core/parser/js/js-scanner-util.c:2345
nullPointerArithmeticRedundantCheck:jerry-core/*.c
nullPointerRedundantCheck:jerry-core/*.c
nullPointerRedundantCheck:jerry-ext/*.c
nullPointerRedundantCheck:jerry-main/*.c
nullPointerRedundantCheck:tests/unit-core/*.c
oppositeInnerCondition:jerry-core/*.c
redundantAssignment:jerry-core/*.c
redundantAssignment:tests/unit-core/test-container-operation.c:129
redundantInitialization:jerry-core/*.c
redundantInitialization:tests/unit-core/test-from-property-descriptor.c:42
shiftNegative:jerry-core/*.c
shiftNegative:jerry-math/*.c
shiftNegativeLHS:jerry-math/*.c
shiftTooManyBits:jerry-core/*.c
shiftTooManyBitsSigned:jerry-math/*.c
signConversionCond:jerry-core/*.c
uninitvar:jerry-core/parser/js/js-parser-expr.c:3420
uninitvar:tests/unit-core/test-api-objecttype.c:119
unmatchedSuppression:jerry-core/*.inc.h
unreadVariable:jerry-core/*.c
unreadVariable:jerry-port/*.c
unusedStructMember:jerry-ext/arg/arg-transform-functions.c
unusedStructMember:jerry-main/*.c
unusedStructMember:tests/unit-core/*.c
variableScope:jerry-math/*.c
wrongmathcall:tests/unit-math/test-math.inc.h
zerodivcond:jerry-core/*.c

0 comments on commit d4c6a42

Please sign in to comment.