Skip to content

Commit 56c2138

Browse files
committed
Merge pull request atomvm#2105 from pguyot/w08/fix-term-non-term-codeql-alerts
Fix term/non-term func CodeQL alerts with casts and proper types These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 2ef6cd2 + 1ccbc6b commit 56c2138

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/libAtomVM/jit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ static term jit_bitstring_extract_integer(
13701370
if (n <= 64) {
13711371
union maybe_unsigned_int64 value;
13721372
bool status = bitstring_extract_integer(
1373-
((term) bin_ptr) | TERM_PRIMARY_BOXED, offset, n, bs_flags, &value);
1373+
(term) (((uintptr_t) bin_ptr) | TERM_PRIMARY_BOXED), offset, n, bs_flags, &value);
13741374
if (UNLIKELY(!status)) {
13751375
return FALSE_ATOM;
13761376
}
@@ -1402,13 +1402,13 @@ static term jit_bitstring_extract_float(Context *ctx, term *bin_ptr, size_t offs
14021402
bool status;
14031403
switch (n) {
14041404
case 16:
1405-
status = bitstring_extract_f16(((term) bin_ptr) | TERM_PRIMARY_BOXED, offset, n, bs_flags, &value);
1405+
status = bitstring_extract_f16((term) (((uintptr_t) bin_ptr) | TERM_PRIMARY_BOXED), offset, n, bs_flags, &value);
14061406
break;
14071407
case 32:
1408-
status = bitstring_extract_f32(((term) bin_ptr) | TERM_PRIMARY_BOXED, offset, n, bs_flags, &value);
1408+
status = bitstring_extract_f32((term) (((uintptr_t) bin_ptr) | TERM_PRIMARY_BOXED), offset, n, bs_flags, &value);
14091409
break;
14101410
case 64:
1411-
status = bitstring_extract_f64(((term) bin_ptr) | TERM_PRIMARY_BOXED, offset, n, bs_flags, &value);
1411+
status = bitstring_extract_f64((term) (((uintptr_t) bin_ptr) | TERM_PRIMARY_BOXED), offset, n, bs_flags, &value);
14121412
break;
14131413
default:
14141414
status = false;

src/libAtomVM/opcodesswitch.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
29752975
// Redo the offset computation and refetch the label
29762976
int label;
29772977
DECODE_LABEL(label, pc)
2978-
int timeout;
2978+
term timeout;
29792979
DECODE_COMPACT_TERM(timeout, pc)
29802980
TRACE("wait_timeout_trap_handler, label: %i\n", label);
29812981
PROCESS_SIGNAL_MESSAGES();
@@ -4511,8 +4511,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
45114511
DECODE_COMPACT_TERM(src, pc);
45124512
term arg2;
45134513
DECODE_COMPACT_TERM(arg2, pc);
4514-
term flags;
4515-
DECODE_LITERAL(flags, pc);
4514+
uint32_t flags_value;
4515+
DECODE_LITERAL(flags_value, pc);
45164516

45174517
#ifdef IMPL_CODE_LOADER
45184518
TRACE("bs_skip_utf16/5\n");
@@ -4528,7 +4528,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
45284528

45294529
int32_t val = 0;
45304530
size_t out_size = 0;
4531-
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags);
4531+
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags_value);
45324532

45334533
if (!is_valid) {
45344534
pc = mod->labels[fail];
@@ -4623,8 +4623,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
46234623
DECODE_COMPACT_TERM(src, pc);
46244624
term arg2;
46254625
DECODE_COMPACT_TERM(arg2, pc);
4626-
term flags;
4627-
DECODE_LITERAL(flags, pc);
4626+
uint32_t flags_value;
4627+
DECODE_LITERAL(flags_value, pc);
46284628

46294629
#ifdef IMPL_CODE_LOADER
46304630
TRACE("bs_skip_utf32/5\n");
@@ -4639,7 +4639,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
46394639
avm_int_t offset_bits = term_get_match_state_offset(src);
46404640

46414641
int32_t val = 0;
4642-
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags);
4642+
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags_value);
46434643

46444644
if (!is_valid) {
46454645
pc = mod->labels[fail];

0 commit comments

Comments
 (0)