From df3556f1614d64ede4e6bd6949524051506826f1 Mon Sep 17 00:00:00 2001 From: jmcmullan Date: Tue, 4 Sep 2012 20:59:10 +0000 Subject: [PATCH] arosc.library: Fix bug in __vcscan where junk characters were accepted as floats Also, add test cases for this in Tests/clib/sscanf Signed-off-by: Jason S. McMullan git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@45732 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/clib/__vcscan.c | 4 +++- test/clib/sscanf.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/compiler/clib/__vcscan.c b/compiler/clib/__vcscan.c index b56a39825b..233eb9e1fa 100644 --- a/compiler/clib/__vcscan.c +++ b/compiler/clib/__vcscan.c @@ -316,8 +316,10 @@ const static unsigned char undef[3][sizeof(double)]= /* Undefined numeric values PREV(c); c=min; } - if(size==1) + if(size==1) { + PREV(c); break; + } if(VAL(tolower(c)=='e')) { diff --git a/test/clib/sscanf.c b/test/clib/sscanf.c index f8d77c903b..ce95fd7e70 100644 --- a/test/clib/sscanf.c +++ b/test/clib/sscanf.c @@ -46,6 +46,20 @@ int main(void) TEST(cnt == 0); TEST(i == 123456); + cnt = sscanf("0.1", "%f", &f); + TEST(cnt == 1); + + cnt = sscanf(".1", "%f", &f); + TEST(cnt == 1); + + cnt = sscanf("1", "%f", &f); + TEST(cnt == 1); + + cnt = sscanf("-.1", "%f", &f); + TEST(cnt == 1); + + cnt = sscanf("x", "%f", &f); + TEST(cnt == 0); return 0; } -- 2.11.4.GIT