Skip to content

Commit 99a9e91

Browse files
committed
Merge pull request #1722 from bettio/fix-get-utf16-utf32
opcodesswitch: fix: OP_BS_GET_UTF16/32 flags decoding 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 db21aaa + ba6a22d commit 99a9e91

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/libAtomVM/bitstring.h

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

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

src/libAtomVM/opcodesswitch.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,8 +4168,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
41684168
DECODE_COMPACT_TERM(src, pc);
41694169
term arg2;
41704170
DECODE_COMPACT_TERM(arg2, pc);
4171-
term flags;
4172-
DECODE_LITERAL(flags, pc);
4171+
uint32_t flags_value;
4172+
DECODE_LITERAL(flags_value, pc);
41734173
DEST_REGISTER(dreg);
41744174
DECODE_DEST_REGISTER(dreg, pc);
41754175

@@ -4178,7 +4178,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
41784178
#endif
41794179

41804180
#ifdef IMPL_EXECUTE_LOOP
4181-
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));
4181+
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));
41824182

41834183
VERIFY_IS_MATCH_STATE(src, "bs_get_utf16");
41844184

@@ -4187,7 +4187,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
41874187

41884188
int32_t val = 0;
41894189
size_t out_size = 0;
4190-
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags);
4190+
bool is_valid = bitstring_match_utf16(src_bin, (size_t) offset_bits, &val, &out_size, flags_value);
41914191

41924192
if (!is_valid) {
41934193
pc = mod->labels[fail];
@@ -4281,8 +4281,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
42814281
DECODE_COMPACT_TERM(src, pc);
42824282
term arg2;
42834283
DECODE_COMPACT_TERM(arg2, pc);
4284-
term flags;
4285-
DECODE_LITERAL(flags, pc);
4284+
uint32_t flags_value;
4285+
DECODE_LITERAL(flags_value, pc);
42864286
DEST_REGISTER(dreg);
42874287
DECODE_DEST_REGISTER(dreg, pc);
42884288

@@ -4291,15 +4291,15 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
42914291
#endif
42924292

42934293
#ifdef IMPL_EXECUTE_LOOP
4294-
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));
4294+
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));
42954295

42964296
VERIFY_IS_MATCH_STATE(src, "bs_get_utf32");
42974297

42984298
term src_bin = term_get_match_state_binary(src);
42994299
avm_int_t offset_bits = term_get_match_state_offset(src);
43004300

43014301
int32_t val = 0;
4302-
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags);
4302+
bool is_valid = bitstring_match_utf32(src_bin, (size_t) offset_bits, &val, flags_value);
43034303

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

0 commit comments

Comments
 (0)