Skip to content

Commit db21aaa

Browse files
committed
Merge pull request #1724 from bettio/fix-cp-codeql-warning
opcodesswitch: fix false positive CodeQL warnings 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 db7fa16 + a235c1e commit db21aaa

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/libAtomVM/context.h

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

107-
unsigned long cp;
107+
term cp;
108108

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

src/libAtomVM/opcodesswitch.h

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

11431143
#define DO_RETURN() \
11441144
{ \
1145-
int module_index = ctx->cp >> 24; \
1145+
int module_index = ((uintptr_t) ctx->cp) >> 24; \
11461146
if (module_index == prev_mod->module_index) { \
11471147
Module *t = mod; \
11481148
mod = prev_mod; \
@@ -1153,7 +1153,7 @@ static void destroy_extended_registers(Context *ctx, unsigned int live)
11531153
mod = globalcontext_get_module_by_index(glb, module_index); \
11541154
code = mod->code->code; \
11551155
} \
1156-
pc = code + ((ctx->cp & 0xFFFFFF) >> 2); \
1156+
pc = code + ((((uintptr_t) ctx->cp) & 0xFFFFFF) >> 2); \
11571157
}
11581158

11591159
#define HANDLE_ERROR() \
@@ -1369,7 +1369,7 @@ static int get_catch_label_and_change_module(Context *ctx, Module **mod)
13691369

13701370
COLD_FUNC static void cp_to_mod_lbl_off(term cp, Context *ctx, Module **cp_mod, int *label, int *l_off)
13711371
{
1372-
Module *mod = globalcontext_get_module_by_index(ctx->global, cp >> 24);
1372+
Module *mod = globalcontext_get_module_by_index(ctx->global, ((uintptr_t) cp) >> 24);
13731373
long mod_offset = (cp & 0xFFFFFF) >> 2;
13741374

13751375
*cp_mod = mod;
@@ -2498,7 +2498,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
24982498
#ifdef IMPL_EXECUTE_LOOP
24992499
TRACE_RETURN(ctx);
25002500

2501-
if ((long) ctx->cp == -1) {
2501+
if ((intptr_t) ctx->cp == -1) {
25022502
return 0;
25032503
}
25042504

@@ -3625,7 +3625,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
36253625
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
36263626
}
36273627
}
3628-
if ((long) ctx->cp == -1) {
3628+
if ((intptr_t) ctx->cp == -1) {
36293629
return 0;
36303630
}
36313631

0 commit comments

Comments
 (0)