diff options
author | Randy Dunlap <rddunlap@osdl.org> | 2002-11-07 22:18:25 -0800 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2002-11-07 22:18:25 -0800 |
commit | fc4088d86bd11dc0b4228ac17f54cf3bda823c41 (patch) | |
tree | 3f9604ace83e3f478904c8bd129ed0c337df807f /lib | |
parent | f81154a9209054d0e0cc7cb7b6954fa8484fb316 (diff) | |
download | history-fc4088d86bd11dc0b4228ac17f54cf3bda823c41.tar.gz |
[PATCH] Fix sscanf("-1", "%d", &i)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/vsprintf.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index b1d4e4a23ccb48..b7e6d06581dc9f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -517,6 +517,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) { const char *str = buf; char *next; + char digit; int num = 0; int qualifier; int base; @@ -638,12 +639,16 @@ int vsscanf(const char * buf, const char * fmt, va_list args) while (isspace(*str)) str++; - if (!*str - || (base == 16 && !isxdigit(*str)) - || (base == 10 && !isdigit(*str)) - || (base == 8 && (!isdigit(*str) || *str > '7')) - || (base == 0 && !isdigit(*str))) - break; + digit = *str; + if (is_sign && digit == '-') + digit = *(str + 1); + + if (!digit + || (base == 16 && !isxdigit(digit)) + || (base == 10 && !isdigit(digit)) + || (base == 8 && (!isdigit(digit) || digit > '7')) + || (base == 0 && !isdigit(digit))) + break; switch(qualifier) { case 'h': |