sourcepawn
sourcepawn copied to clipboard
Passing slices to fixed-size params has an unclear error
#include <sourcemod>
void test(char buffer[9]) {
PrintToServer("%s", buffer);
}
public void OnPluginStart()
{
char big[2048];
test(big);
test(big[0]);
test(big[1]);
}
In 1.10, the slices are ignored for size checking:
SourcePawn Compiler 1.10
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2018 AlliedModders LLC
plugin.sp(10) : error 047: array sizes do not match, or destination array is too small
1 Error.
In 1.11+ they now throw error 047 as well:
SourcePawn Compiler 1.12
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2021 AlliedModders LLC
silvers.sp(10) : error 047: array sizes do not match, or destination array is too small
silvers.sp(11) : error 047: array sizes do not match, or destination array is too small
silvers.sp(12) : error 047: array sizes do not match, or destination array is too small
3 Errors.
This change seems good from a correctness PoV, the slice could obviously be the wrong size and we can't sanely check it - but as a behaviour change I think we could do with a more clear error message specific to params, it wasn't clear to the original author what needed to be changed.
#642 surfaced this as an error, as previously the assert there was silent in release builds. I built 1.5.4-dev+b9959f6b and that still had the assert, so it looks like this was indeed probably never meant to work, it was just missing the error until the assert was cleaned up recently.