Skip to content

Commit fb8f156

Browse files
committed
Forward port changes from v0.6 release branch
Merge from release-0.6 changes aimed to fix some false positive CodeQL warnings.
2 parents eecfae9 + 99a9e91 commit fb8f156

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/libAtomVM/bitstring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ extern "C" {
8888
)
8989
#endif
9090

91+
// do not change the values
92+
// these values are the same used from opcodes such as bs_get_utf16
9193
enum BitstringFlags
9294
{
9395
LittleEndianInteger = 0x2,

src/libAtomVM/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct Context
105105
size_t max_heap_size;
106106
enum HeapGrowthStrategy heap_growth_strategy;
107107

108-
unsigned long cp;
108+
term cp;
109109

110110
// saved state when scheduled out
111111
Module *saved_module;

src/libAtomVM/opcodesswitch.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ static void destroy_extended_registers(Context *ctx, unsigned int live)
11681168

11691169
#define DO_RETURN() \
11701170
{ \
1171-
int module_index = ctx->cp >> 24; \
1171+
int module_index = ((uintptr_t) ctx->cp) >> 24; \
11721172
if (module_index == prev_mod->module_index) { \
11731173
Module *t = mod; \
11741174
mod = prev_mod; \
@@ -1179,7 +1179,7 @@ static void destroy_extended_registers(Context *ctx, unsigned int live)
11791179
mod = globalcontext_get_module_by_index(glb, module_index); \
11801180
code = mod->code->code; \
11811181
} \
1182-
pc = code + ((ctx->cp & 0xFFFFFF) >> 2); \
1182+
pc = code + ((((uintptr_t) ctx->cp) & 0xFFFFFF) >> 2); \
11831183
}
11841184

11851185
#define HANDLE_ERROR() \
@@ -1395,7 +1395,7 @@ static int get_catch_label_and_change_module(Context *ctx, Module **mod)
13951395

13961396
COLD_FUNC static void cp_to_mod_lbl_off(term cp, Context *ctx, Module **cp_mod, int *label, int *l_off)
13971397
{
1398-
Module *mod = globalcontext_get_module_by_index(ctx->global, cp >> 24);
1398+
Module *mod = globalcontext_get_module_by_index(ctx->global, ((uintptr_t) cp) >> 24);
13991399
long mod_offset = (cp & 0xFFFFFF) >> 2;
14001400

14011401
*cp_mod = mod;
@@ -2590,7 +2590,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
25902590
#ifdef IMPL_EXECUTE_LOOP
25912591
TRACE_RETURN(ctx);
25922592

2593-
if ((long) ctx->cp == -1) {
2593+
if ((intptr_t) ctx->cp == -1) {
25942594
return 0;
25952595
}
25962596

@@ -3715,7 +3715,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
37153715
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
37163716
}
37173717
}
3718-
if ((long) ctx->cp == -1) {
3718+
if ((intptr_t) ctx->cp == -1) {
37193719
return 0;
37203720
}
37213721

@@ -4285,8 +4285,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
42854285
DECODE_COMPACT_TERM(src, pc);
42864286
term arg2;
42874287
DECODE_COMPACT_TERM(arg2, pc);
4288-
term flags;
4289-
DECODE_LITERAL(flags, pc);
4288+
uint32_t flags_value;
4289+
DECODE_LITERAL(flags_value, pc);
42904290
DEST_REGISTER(dreg);
42914291
DECODE_DEST_REGISTER(dreg, pc);
42924292

@@ -4295,7 +4295,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
42954295
#endif
42964296

42974297
#ifdef IMPL_EXECUTE_LOOP
4298-
TRACE("bs_get_utf16/5, fail=%i src=0x%lx arg2=0x%lx flags=0x%lx dreg=%c%i\n", fail, src, arg2, flags, T_DEST_REG(dreg));
4298+
TRACE("bs_get_utf16/5, fail=%i src=0x%lx arg2=0x%lx flags=0x%"PRIu32" dreg=%c%i\n", fail, src, arg2, flags_value, T_DEST_REG(dreg));
42994299

43004300
VERIFY_IS_MATCH_STATE(src, "bs_get_utf16");
43014301

@@ -4304,7 +4304,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
43044304

43054305
int32_t val = 0;
43064306
size_t out_size = 0;
4307-
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags);
4307+
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags_value);
43084308

43094309
if (!is_valid) {
43104310
pc = mod->labels[fail];
@@ -4398,8 +4398,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
43984398
DECODE_COMPACT_TERM(src, pc);
43994399
term arg2;
44004400
DECODE_COMPACT_TERM(arg2, pc);
4401-
term flags;
4402-
DECODE_LITERAL(flags, pc);
4401+
uint32_t flags_value;
4402+
DECODE_LITERAL(flags_value, pc);
44034403
DEST_REGISTER(dreg);
44044404
DECODE_DEST_REGISTER(dreg, pc);
44054405

@@ -4408,15 +4408,15 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
44084408
#endif
44094409

44104410
#ifdef IMPL_EXECUTE_LOOP
4411-
TRACE("bs_get_utf32/5, fail=%i src=0x%lx arg2=0x%lx flags=0x%lx dreg=%c%i\n", fail, src, arg2, flags, T_DEST_REG(dreg));
4411+
TRACE("bs_get_utf32/5, fail=%i src=0x%lx arg2=0x%lx flags=0x%"PRIu32" dreg=%c%i\n", fail, src, arg2, flags_value, T_DEST_REG(dreg));
44124412

44134413
VERIFY_IS_MATCH_STATE(src, "bs_get_utf32");
44144414

44154415
term src_bin = term_get_match_state_binary(src);
44164416
avm_int_t offset_bits = term_get_match_state_offset(src);
44174417

44184418
int32_t val = 0;
4419-
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags);
4419+
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags_value);
44204420

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

0 commit comments

Comments
 (0)