summaryrefslogtreecommitdiff
path: root/npc
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-05-16 04:58:16 +0200
committerHaru <haru@dotalux.com>2016-06-25 17:29:42 +0200
commitba035696cf0927624b02db5573c617566cdd645f (patch)
tree10e29b4e98df8de94e3e867d037e9a031df73b73 /npc
parentef7f1cbcaf893961d9e8e053ec666602645111df (diff)
downloadhercules-ba035696cf0927624b02db5573c617566cdd645f.tar.gz
hercules-ba035696cf0927624b02db5573c617566cdd645f.tar.bz2
hercules-ba035696cf0927624b02db5573c617566cdd645f.tar.xz
hercules-ba035696cf0927624b02db5573c617566cdd645f.zip
Re-implemented BUILDIN(sprintf)
- The function now checks its arguments, rather than passing them to the system implementation (safer against arbitrary memory access or wrong variable type) - Implemented positional ('%1$d') specifiers (POSIX style) - See script_commands.txt for details about the supported format specifiers. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'npc')
-rw-r--r--npc/dev/test.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/npc/dev/test.txt b/npc/dev/test.txt
index 72cf86616..ee2bda259 100644
--- a/npc/dev/test.txt
+++ b/npc/dev/test.txt
@@ -711,6 +711,24 @@ function script HerculesSelfTestHelper {
callsub(OnCheck, "Callfunc (return NPC variables from another NPC)", callfunc("F_TestVarOfAnotherNPC", "TestVarOfAnotherNPC"), 1);
callsub(OnCheck, "Callfunc (return NPC variables from another NPC - local variable overwrite check)", .x, 2);
+ callsub(OnCheckStr, "sprintf (%%)", sprintf("'%%'"), "'%'");
+ callsub(OnCheckStr, "sprintf (%d)", sprintf("'%d'", 5), "'5'");
+ callsub(OnCheckStr, "sprintf (neg. %d)", sprintf("'%d'", -5), "'-5'");
+ callsub(OnCheckStr, "sprintf (%u)", sprintf("'%u'", 5), "'5'");
+ callsub(OnCheckStr, "sprintf (%x)", sprintf("'%x'", 10), "'a'");
+ callsub(OnCheckStr, "sprintf (%X)", sprintf("'%X'", 31), "'1F'");
+ callsub(OnCheckStr, "sprintf (%s)", sprintf("'%s'", "Hello World!"), "'Hello World!'");
+ callsub(OnCheckStr, "sprintf (%c)", sprintf("'%c'", "Hello World!"), "'H'");
+ callsub(OnCheckStr, "sprintf (%+d)", sprintf("'%+d'", 5), "'+5'");
+ callsub(OnCheckStr, "sprintf (%{n}d)", sprintf("'%5d'", 5), "' 5'");
+ callsub(OnCheckStr, "sprintf (%-{n}d)", sprintf("'%-5d'", 5), "'5 '");
+ callsub(OnCheckStr, "sprintf (%-+{n}d)", sprintf("'%-+5d'", 5), "'+5 '");
+ callsub(OnCheckStr, "sprintf (%+0{n}d)", sprintf("'%+05d'", 5), "'+0005'");
+ callsub(OnCheckStr, "sprintf (%0*d)", sprintf("'%0*d'", 5, 10), "'00010'");
+ callsub(OnCheckStr, "sprintf (Two args)", sprintf("'%+05d' '%x'", 5, 0x7f), "'+0005' '7f'");
+ callsub(OnCheckStr, "sprintf (positional)", sprintf("'%2$+05d'", 5, 6), "'+0006'");
+ callsub(OnCheckStr, "sprintf (positional)", sprintf("'%2$s' '%1$c'", "First", "Second"), "'Second' 'F'");
+
if (.errors) {
debugmes "Script engine self-test [ \033[0;31mFAILED\033[0m ]";
debugmes "**** The test was completed with " + .errors + " errors. ****";