Handle NULLs in SDKCall string return (Fixes #874) (#906)

`SDKCall` has existing semantics that a `-1` retval indicates null, so use that and writes an empty string to the buffer.

Consumers can tell the difference between `""` and `NULL` by checking if the return value is `0` or `-1`.
This commit is contained in:
Asher Baker 2018-10-11 00:18:03 +01:00 committed by GitHub
parent a659896f8a
commit a1271ec3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -449,6 +449,11 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
cell_t *addr; cell_t *addr;
size_t written; size_t written;
pContext->LocalToPhysAddr(params[retparam+1], &addr); pContext->LocalToPhysAddr(params[retparam+1], &addr);
if (!(*(char **)vc->retbuf))
{
pContext->StringToLocalUTF8(params[retparam], *addr, "", &written);
return -1;
}
pContext->StringToLocalUTF8(params[retparam], *addr, *(char **)vc->retbuf, &written); pContext->StringToLocalUTF8(params[retparam], *addr, *(char **)vc->retbuf, &written);
return (cell_t)written; return (cell_t)written;
} else if (vc->retinfo->vtype == Valve_Vector } else if (vc->retinfo->vtype == Valve_Vector