From d867a95fd672898f7f0d05014e63e255521cf2e3 Mon Sep 17 00:00:00 2001 From: Vincent Herbet Date: Fri, 28 Sep 2018 16:39:03 +0200 Subject: [PATCH] Fix a crash with set_tr/2 when -1 is passed in TR_pHit + allow worldspawn (0) in set_tr/2 (#601) * Fix a crash with set_ptr2 when -1 is passed in TR_pHit * Allow wordspawn in set_tr|2(TR_pHit, ...) --- modules/fakemeta/fm_tr.cpp | 12 ++++++------ modules/fakemeta/fm_tr2.cpp | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/fakemeta/fm_tr.cpp b/modules/fakemeta/fm_tr.cpp index 6b735f06..1bd9d671 100644 --- a/modules/fakemeta/fm_tr.cpp +++ b/modules/fakemeta/fm_tr.cpp @@ -27,7 +27,6 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) } cell *ptr = MF_GetAmxAddr(amx, params[2]); - edict_t *e; switch (type) { @@ -85,12 +84,13 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params) } case TR_pHit: { - e = TypeConversion.id_to_edict(*ptr); - if (*ptr != -1 && FNullEnt(e)) - return 0; //TODO: return error - gfm_tr->pHit = e; + const auto pEdict = TypeConversion.id_to_edict(*ptr); + if (pEdict == nullptr) + { + return 0; + } + gfm_tr->pHit = pEdict; return 1; - break; } case TR_iHitgroup: { diff --git a/modules/fakemeta/fm_tr2.cpp b/modules/fakemeta/fm_tr2.cpp index 57db06c9..4b5a0e07 100644 --- a/modules/fakemeta/fm_tr2.cpp +++ b/modules/fakemeta/fm_tr2.cpp @@ -98,12 +98,13 @@ static cell AMX_NATIVE_CALL set_tr2(AMX *amx, cell *params) } case TR_pHit: { - edict_t *e = TypeConversion.id_to_edict(*ptr); - if (*ptr != -1 && FNullEnt(e)) - return 0; //TODO: return error - tr->pHit = e; + const auto pEdict = TypeConversion.id_to_edict(*ptr); + if (pEdict == nullptr) + { + return 0; + } + tr->pHit = pEdict; return 1; - break; } case TR_iHitgroup: {