Skip to content

Commit ef4cb2b

Browse files
authored
Update cppcheck (#5108)
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 Refactor test-snapshot: move each test to separate functions like some others already were. Rename `handler` variables inside `main` of `test-api.c` as they shadowed the `handler` function in the same file. JerryScript-DCO-1.0-Signed-off-by: Máté Tokodi [email protected]
1 parent ff9ff8f commit ef4cb2b

File tree

9 files changed

+270
-212
lines changed

9 files changed

+270
-212
lines changed

.github/workflows/gh-actions.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
python-version: '3.10'
1818
- run: sudo apt update
1919
# TODO: update checkers to current versions available in ubuntu 22.04
20-
# - run: sudo apt install clang-format-10 cppcheck python-serial
21-
- run: sudo apt install pylint doxygen
20+
# - run: sudo apt install clang-format-10 python-serial
21+
- run: sudo apt install pylint doxygen cppcheck
2222
- run: $RUNNER --check-signed-off=gh-actions
2323
if: ${{ always() }}
2424
- run: $RUNNER --check-doxygen
@@ -31,8 +31,8 @@ jobs:
3131
# if: ${{ always() }}
3232
- run: $RUNNER --check-pylint
3333
if: ${{ always() }}
34-
# - run: $RUNNER --check-cppcheck
35-
# if: ${{ always() }}
34+
- run: $RUNNER --check-cppcheck
35+
if: ${{ always() }}
3636

3737
Linux_x86-64_Build_Correctness_Debugger_Tests:
3838
runs-on: ubuntu-latest

jerry-core/ecma/base/ecma-helpers-errol.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,24 @@ ecma_errol0_dtoa (double val, /**< ecma number */
143143
int32_t *exp_p) /**< [out] exponent */
144144
{
145145
double power_of_10 = 1.0;
146-
int32_t exp = 1;
146+
int32_t exponent = 1;
147147

148148
/* normalize the midpoint */
149149
ecma_high_prec_t mid;
150150

151151
mid.value = val;
152152
mid.offset = 0.0;
153153

154-
while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exp < 308))
154+
while (((mid.value > 10.0) || ((mid.value == 10.0) && (mid.offset >= 0.0))) && (exponent < 308))
155155
{
156-
exp++;
156+
exponent++;
157157
ecma_divide_high_prec_by_10 (&mid);
158158
power_of_10 /= 10.0;
159159
}
160160

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

186186
while (high_bound.value > 10.0 || (high_bound.value == 10.0 && (high_bound.offset >= 0.0)))
187187
{
188-
exp++;
188+
exponent++;
189189
ecma_divide_high_prec_by_10 (&high_bound);
190190
ecma_divide_high_prec_by_10 (&low_bound);
191191
}
192192

193193
while (high_bound.value < 1.0 || (high_bound.value == 1.0 && (high_bound.offset < 0.0)))
194194
{
195-
exp--;
195+
exponent--;
196196
ecma_multiply_high_prec_by_10 (&high_bound);
197197
ecma_multiply_high_prec_by_10 (&low_bound);
198198
}
@@ -234,7 +234,7 @@ ecma_errol0_dtoa (double val, /**< ecma number */
234234
double mdig = (high_bound.value + low_bound.value) / 2.0 + 0.5;
235235
*dst_p++ = (lit_utf8_byte_t) ('0' + (uint8_t) mdig);
236236

237-
*exp_p = exp;
237+
*exp_p = exponent;
238238

239239
return (lit_utf8_size_t) (dst_p - buffer_p);
240240
} /* ecma_errol0_dtoa */

jerry-ext/handle-scope/handle-scope.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ jerryx_escape_handle_internal (jerryx_escapable_handle_scope scope,
254254
* Escape handle to parent scope
255255
*/
256256
*result = jerryx_handle_scope_add_handle_to (found_handle, parent);
257-
}
258257

259-
if (should_promote)
260-
{
261258
scope->escaped = true;
262259
}
263260
return jerryx_handle_scope_ok;

jerry-ext/util/sources.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ jerryx_source_exec_stdin (void)
146146

147147
jerry_size_t new_size = source_size + line_size;
148148
source_p = realloc (source_p, new_size);
149+
if (source_p == NULL)
150+
{
151+
return jerry_throw_sz (JERRY_ERROR_COMMON, "Out of memory.");
152+
}
149153

150154
memcpy (source_p + source_size, line_p, line_size);
151155
jerry_port_line_free (line_p);

jerry-port/common/jerry-port-io.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ jerry_port_line_read (jerry_size_t *out_size_p)
7171
{
7272
allocated += 64;
7373
line_p = realloc (line_p, allocated);
74+
if (line_p == NULL)
75+
{
76+
jerry_port_fatal (JERRY_FATAL_OUT_OF_MEMORY);
77+
}
7478

7579
while (bytes < allocated - 1)
7680
{

tests/unit-core/test-api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,12 @@ main (void)
709709
if (jerry_feature_enabled (JERRY_FEATURE_PROXY))
710710
{
711711
jerry_value_t target = jerry_object ();
712-
jerry_value_t handler = jerry_object ();
713-
jerry_value_t proxy = jerry_proxy (target, handler);
712+
jerry_value_t proxy_handler = jerry_object ();
713+
jerry_value_t proxy = jerry_proxy (target, proxy_handler);
714714
jerry_value_t obj_proto = jerry_eval ((jerry_char_t *) "Object.prototype", 16, JERRY_PARSE_NO_OPTS);
715715

716716
jerry_value_free (target);
717-
jerry_value_free (handler);
717+
jerry_value_free (proxy_handler);
718718
proto_val = jerry_object_proto (proxy);
719719
TEST_ASSERT (!jerry_value_is_exception (proto_val));
720720
TEST_ASSERT (proto_val == obj_proto);
@@ -745,8 +745,8 @@ main (void)
745745
if (jerry_feature_enabled (JERRY_FEATURE_PROXY))
746746
{
747747
jerry_value_t target = jerry_object ();
748-
jerry_value_t handler = jerry_object ();
749-
jerry_value_t proxy = jerry_proxy (target, handler);
748+
jerry_value_t proxy_handler = jerry_object ();
749+
jerry_value_t proxy = jerry_proxy (target, proxy_handler);
750750
new_proto = jerry_eval ((jerry_char_t *) "Function.prototype", 18, JERRY_PARSE_NO_OPTS);
751751

752752
res = jerry_object_set_proto (proxy, new_proto);
@@ -755,7 +755,7 @@ main (void)
755755
TEST_ASSERT (target_proto == new_proto);
756756

757757
jerry_value_free (target);
758-
jerry_value_free (handler);
758+
jerry_value_free (proxy_handler);
759759
jerry_value_free (proxy);
760760
jerry_value_free (new_proto);
761761
jerry_value_free (target_proto);

0 commit comments

Comments
 (0)