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, ...)
This commit is contained in:
Vincent Herbet 2018-09-28 16:39:03 +02:00 committed by GitHub
parent 49430082f5
commit f1f95425b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 11 deletions

View File

@ -27,7 +27,6 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
} }
cell *ptr = MF_GetAmxAddr(amx, params[2]); cell *ptr = MF_GetAmxAddr(amx, params[2]);
edict_t *e;
switch (type) switch (type)
{ {
@ -85,12 +84,13 @@ static cell AMX_NATIVE_CALL set_tr(AMX *amx, cell *params)
} }
case TR_pHit: case TR_pHit:
{ {
e = TypeConversion.id_to_edict(*ptr); const auto pEdict = TypeConversion.id_to_edict(*ptr);
if (*ptr != -1 && FNullEnt(e)) if (pEdict == nullptr)
return 0; //TODO: return error {
gfm_tr->pHit = e; return 0;
}
gfm_tr->pHit = pEdict;
return 1; return 1;
break;
} }
case TR_iHitgroup: case TR_iHitgroup:
{ {

View File

@ -98,12 +98,13 @@ static cell AMX_NATIVE_CALL set_tr2(AMX *amx, cell *params)
} }
case TR_pHit: case TR_pHit:
{ {
edict_t *e = TypeConversion.id_to_edict(*ptr); const auto pEdict = TypeConversion.id_to_edict(*ptr);
if (*ptr != -1 && FNullEnt(e)) if (pEdict == nullptr)
return 0; //TODO: return error {
tr->pHit = e; return 0;
}
tr->pHit = pEdict;
return 1; return 1;
break;
} }
case TR_iHitgroup: case TR_iHitgroup:
{ {