Permalink
Browse files

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`.
  • Loading branch information...
asherkin committed Oct 10, 2018
1 parent 0cdc361 commit e27e75b197c7b0bc631c9aec50b307745087d5e6
Showing with 5 additions and 0 deletions.
  1. +5 −0 extensions/sdktools/vcaller.cpp
@@ -445,6 +445,11 @@ static cell_t SDKCall(IPluginContext *pContext, const cell_t *params)
cell_t *addr;
size_t written;
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);
return (cell_t)written;
} else if (vc->retinfo->vtype == Valve_Vector

0 comments on commit e27e75b

Please sign in to comment.