Skip to content

Commit 5d59fd3

Browse files
committed
libscript: Don't mix enum types.
The on-disk value saved in the compiled LCB bytecode for the mode of a handler parameter (`in`/`out`/`inout`) is described by the `MCScriptHandlerTypeParameterMode` enumeration. However, when constructing an `MCHandlerTypeInfo` value for use at runtime, these values need to be translated to the `MCHandlerTypeFieldMode` enumeration. This patch adds an explicit `inline` conversion method to the `MCScriptHandlerTypeParameter` structure. Coverity-Id: 16984
1 parent 0de9d03 commit 5d59fd3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libscript/src/script-module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ bool MCScriptEnsureModuleIsUsable(MCScriptModuleRef self)
728728
for(uindex_t j = 0; j < t_type -> parameter_count; j++)
729729
{
730730
MCHandlerTypeFieldInfo t_parameter;
731-
t_parameter . mode = (MCHandlerTypeFieldMode)t_type -> parameters[j] . mode;
731+
t_parameter . mode = t_type -> parameters[j] . GetFieldMode();
732732
t_parameter . type = self -> types[t_type -> parameters[j] . type] -> typeinfo;
733733
if (!t_parameters . Push(t_parameter))
734734
goto error_cleanup;

libscript/src/script-private.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ struct MCScriptHandlerTypeParameter
155155
{
156156
MCScriptHandlerTypeParameterMode mode;
157157
uindex_t type;
158+
159+
/* Translate the mode of this parameter from a
160+
* MCScriptHandlerTypeParameterMode to an
161+
* MCHandlerTypeFieldMode. */
162+
inline MCHandlerTypeFieldMode GetFieldMode() const
163+
{
164+
switch (mode)
165+
{
166+
case kMCScriptHandlerTypeParameterModeIn:
167+
return kMCHandlerTypeFieldModeIn;
168+
case kMCScriptHandlerTypeParameterModeOut:
169+
return kMCHandlerTypeFieldModeOut;
170+
case kMCScriptHandlerTypeParameterModeInOut:
171+
return kMCHandlerTypeFieldModeInOut;
172+
default:
173+
MCUnreachableReturn(kMCHandlerTypeFieldModeIn);
174+
}
175+
}
158176
};
159177

160178
struct MCScriptHandlerType: public MCScriptType

0 commit comments

Comments
 (0)