alliedmodders/sourcemod — pull request #132 by dvander (2014-08-17 08:22:09+00:00)
Title: Fix returning strings from functions with variadic arguments.

Another offshoot of Pawn's compiler design - returning strings from a function allocates a hidden parameter. That's fine, but the parameter is at the *end* of the argument list, rather than the beginning. If the function is variadic, the compiler treats the entire `...` as one static argument. Hijinks ensue.

This patch detects when a string is about to be returned from a variadic function, and dynamically computes where the last argument is. That turns out to be a simple case of taking the argcount and adding it to the address of the first argument.

Testcase:
```
native print(const char[] fmt, any:...)

stock String:f(a, b, c, ...)
{
new String:str[] = "hello"
return str
}

public main()
{
print(f(1, 2, 3, 3, 1, 3, 4, 1, 6, 3, 9))
}
```