Skip to content

Commit d4a0cda

Browse files
committed
[[ Script ]] Fix bytecode op argument decode / encode.
1 parent f1d0e26 commit d4a0cda

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

libscript/src/script-builder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,9 @@ static void __emit_bytecode_uint(MCScriptModuleBuilderRef self, uindex_t p_value
924924
if ((p_value & (1 << 31)) != 0)
925925
{
926926
p_value &= ~(1 << 31);
927-
t_bytes[0] = ((p_value >> 7) & 0x7f) | 0x80;
928-
t_bytes[1] = (p_value & 0x7f);
927+
928+
t_bytes[0] = (p_value & 0x7f) | 0x80;
929+
t_bytes[1] = ((p_value >> 7) & 0x7f);
929930
t_index = 2;
930931

931932
if ((p_value >> 14) != 0)

libscript/src/script-instance.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,13 +539,16 @@ static inline uindex_t MCScriptBytecodeDecodeArgument(byte_t*& x_bytecode_ptr)
539539
{
540540
uindex_t t_value;
541541
t_value = 0;
542+
int t_shift;
543+
t_shift = 0;
542544
for(;;)
543545
{
544546
byte_t t_next;
545547
t_next = *x_bytecode_ptr++;
546-
t_value = (t_value << 7) | (t_next & 0x7f);
548+
t_value |= (t_next & 0x7f) << t_shift;
547549
if ((t_next & 0x80) == 0)
548550
break;
551+
t_shift += 7;
549552
}
550553
return t_value;
551554
}
@@ -662,7 +665,7 @@ static bool MCScriptPerformScriptInvoke(MCScriptFrame*& x_frame, byte_t*& x_next
662665
t_signature = p_instance -> module -> types[p_handler -> type] -> typeinfo;
663666

664667
if (MCHandlerTypeInfoGetParameterCount(t_signature) != p_arity)
665-
return MCScriptThrowWrongNumberOfArgumentsForInvokeError(x_frame -> instance -> module, x_frame -> address, p_handler, p_arity - 1);
668+
return MCScriptThrowWrongNumberOfArgumentsForInvokeError(x_frame -> instance -> module, x_frame -> address, p_handler, p_arity);
666669

667670
for(uindex_t i = 0; i < p_arity; i++)
668671
{

0 commit comments

Comments
 (0)