From 4cdfd7ebba0bf03098c729b9e3ec24dfee09b7d6 Mon Sep 17 00:00:00 2001 From: Walter Agazzi Date: Mon, 16 Sep 2024 13:17:12 +0200 Subject: [PATCH] AGS: Engine: in cc_instance, use static_cast where possible From upstream 13835765706f16affd1e2a43015a967a73fe04f3 --- engines/ags/engine/script/cc_instance.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp index 74331cf83d4..0cd10a6e0ed 100644 --- a/engines/ags/engine/script/cc_instance.cpp +++ b/engines/ags/engine/script/cc_instance.cpp @@ -516,7 +516,7 @@ inline bool FixupArgument(RuntimeScriptValue &arg, const int fixup, const uintpt // originally commented -- CHECKME: could this be used in very old versions of AGS? // code[fixup] += (long)&code[0]; // This is a program counter value, presumably will be used as SCMD_CALL argument - arg.SetInt32((int32_t)code); + arg.SetInt32(static_cast(code)); return true; case FIXUP_STRING: arg.SetStringLiteral(strings + code); @@ -534,7 +534,7 @@ inline bool FixupArgument(RuntimeScriptValue &arg, const int fixup, const uintpt case FIXUP_DATADATA: return false; // placeholder, fail at this as not supposed to be here case FIXUP_STACK: - arg = GetStackPtrOffsetFw(stack, (int32_t)code); + arg = GetStackPtrOffsetFw(stack, static_cast(code)); return true; default: cc_error("internal fixup type error: %d", fixup); @@ -600,13 +600,13 @@ int ccInstance::Run(int32_t curpc) { switch (codeOp.ArgCount) { case 3: - codeOp.Args[2].SetInt32((int32_t)codeInst->code[pc + 3]); + codeOp.Args[2].SetInt32(static_cast(codeInst->code[pc + 3])); /* fall-through */ case 2: - codeOp.Args[1].SetInt32((int32_t)codeInst->code[pc + 2]); + codeOp.Args[1].SetInt32(static_cast(codeInst->code[pc + 2])); /* fall-through */ case 1: - codeOp.Args[0].SetInt32((int32_t)codeInst->code[pc + 1]); + codeOp.Args[0].SetInt32(static_cast(codeInst->code[pc + 1])); break; default: break; @@ -1168,7 +1168,7 @@ int ccInstance::Run(int32_t curpc) { } callAddr /= sizeof(intptr_t); // size of ccScript::code elements - if (Run((int32_t)callAddr)) + if (Run(static_cast(callAddr))) return -1; runningInst = wasRunning; @@ -1605,14 +1605,14 @@ bool ccInstance::_Create(PScript scri, const ccInstance *joined) { globaldatasize = scri->globaldatasize; globaldata = nullptr; if (globaldatasize > 0) { - globaldata = (char *)malloc(globaldatasize); + globaldata = static_cast(malloc(globaldatasize)); memcpy(globaldata, scri->globaldata, globaldatasize); } codesize = scri->codesize; code = nullptr; if (codesize > 0) { - code = (intptr_t *)malloc(codesize * sizeof(intptr_t)); + code = static_cast(malloc(codesize * sizeof(intptr_t))); // 64 bit: Read code into 8 byte array, necessary for being able to perform // relocations on the references. for (int i = 0; i < codesize; ++i) @@ -1669,7 +1669,7 @@ bool ccInstance::_Create(PScript scri, const ccInstance *joined) { if (etype == EXPORT_FUNCTION) { // NOTE: unfortunately, there seems to be no way to know if // that's an extender function that expects object pointer - exports[i].SetCodePtr(((intptr_t)eaddr * sizeof(intptr_t) + reinterpret_cast(&code[0]))); + exports[i].SetCodePtr((static_cast(eaddr) * sizeof(intptr_t) + reinterpret_cast(&code[0]))); } else if (etype == EXPORT_DATA) { ScriptVariable *gl_var = FindGlobalVar(eaddr); if (gl_var) { @@ -1910,9 +1910,9 @@ bool ccInstance::CreateRuntimeCodeFixups(const ccScript *scri) { code_fixups[fixup] = scri->fixuptypes[i]; switch (scri->fixuptypes[i]) { case FIXUP_GLOBALDATA: { - ScriptVariable *gl_var = FindGlobalVar((int32_t)code[fixup]); + ScriptVariable *gl_var = FindGlobalVar(static_cast(code[fixup])); if (!gl_var) { - cc_error_fixups(scri, fixup, "cannot resolve global variable (bytecode pos %d, key %d)", fixup, (int32_t)code[fixup]); + cc_error_fixups(scri, fixup, "cannot resolve global variable (bytecode pos %d, key %d)", fixup, static_cast(code[fixup])); return false; } code[fixup] = (intptr_t)gl_var;