Issue information

Issue ID
#8009
Status
Fixed
Severity
None
Started
AnnieRuru
Feb 6, 2014 19:46
Last Post
Haru
Feb 8, 2014 1:49
Confirmation
Yes (1)
No (0)

AnnieRuru - Feb 6, 2014 19:46

I just switch to hercules, and tested having the same bug here

[url="http://rathena.org/board/tracker/issue-8562-sscanf-should-return-1-if-the-string-field-is-an-empty-string/"]http://rathena.org/board/tracker/issue-8562-sscanf-should-return-1-if-the-string-field-is-an-empty-string/[/url]

rathena already fixed this bug
so you guys can just do as copy-cat

[url="https://github.com/HerculesWS/Hercules/blob/master/src/map/script.c#L14137"]https://github.com/HerculesWS/Hercules/blob/master/src/map/script.c#L14137[/url]
change[code=auto:0]script_pushint(st, arg);[/code]into[code=auto:0]if ( strlen( str ) ) script_pushint(st, arg); else script_pushint(st, -1);[/code]

Haru - Feb 6, 2014 22:21

There's one case that's not covered by that fix (unless I'm reading it wrong).

In both GNU (i.e. Linux) and xnu (i.e. Mac OS) implementations, if sscanf doesn't receive any format specifiers, the return value is always zero (because zero conversions were attempted), even if the input string is empty.[code=auto:0] printf("%d\n", sscanf("", "")); [/code]outputs 0.

It really is an edge case, but I think we should cover it, since it is meant to be the same as the C sscanf. (source from the OSX version [url="http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/libkern/stdio/scanf.c"]here[/url])

A compliant fix would be:[code=auto:0] if ( strlen(str) == 0 && strlen(format) != 0 ) script_pushint(st, -1); else script_pushint(st, arg); [/code](optimizations are possible, to just return 0 without even trying to parse the format specifier when its length is zero)

Haru - Feb 8, 2014 1:49

Fixed as part of commit [url="https://github.com/HerculesWS/Hercules/commit/1cf7c1ec251d6899707b0eced3bc75da2e212557"]https://github.com/HerculesWS/Hercules/commit/1cf7c1ec251d6899707b0eced3bc75da2e212557[/url] (including the above mentioned optimization) - thank you!