diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-21 23:30:28 +0200 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-21 23:30:28 +0200 |
commit | 04f0f1cc551736668758fe9d03cea861ee87dfd1 (patch) | |
tree | 8992b05ead7e638498ce0fe730a3386608ce6548 /nuttx | |
parent | 291d0b36d3c68af90efbed4662b28fb941633327 (diff) | |
download | px4-nuttx-04f0f1cc551736668758fe9d03cea861ee87dfd1.tar.gz px4-nuttx-04f0f1cc551736668758fe9d03cea861ee87dfd1.tar.bz2 px4-nuttx-04f0f1cc551736668758fe9d03cea861ee87dfd1.zip |
Fixed two sscanf() issues: 1) sscanf() always reported as result value the number of wanted arguments, even if it was not able to get all of them. 2) sscanf() would return conversion success for the last argument even if the last character is a space symbol
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/libc/stdio/lib_sscanf.c | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/nuttx/libc/stdio/lib_sscanf.c b/nuttx/libc/stdio/lib_sscanf.c index e6ba5b5e8..bc5953f2d 100644 --- a/nuttx/libc/stdio/lib_sscanf.c +++ b/nuttx/libc/stdio/lib_sscanf.c @@ -271,12 +271,15 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) * bytes remaining in the input data stream. */ + /* Skip over any white space before the string */ + + while (*buf && isspace(*buf)) + { + buf++; + } + if (*buf) { - while (isspace(*buf)) - { - buf++; - } /* Was a fieldwidth specified? */ @@ -299,6 +302,10 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) buf += width; } + else + { + noassign = true; + } } /* Process %c: Character conversion */ @@ -348,6 +355,10 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) buf += width; } + else + { + noassign = true; + } } /* Process %d, %o, %b, %x, %u: Various integer conversions */ @@ -385,14 +396,15 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) * bytes remaining in the input data stream. */ - if (*buf) + /* Skip over any white space before the integer string */ + + while (*buf && isspace(*buf)) { - /* Skip over any white space before the integer string */ + buf++; + } - while (isspace(*buf)) - { - buf++; - } + if (*buf) + { /* The base of the integer conversion depends on the * specific conversion specification. @@ -462,6 +474,10 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) } } } + else + { + noassign = true; + } } /* Process %f: Floating point conversion */ @@ -504,14 +520,15 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) * bytes remaining in the input data stream. */ - if (*buf) + /* Skip over any white space before the real string */ + + while (*buf && isspace(*buf)) { - /* Skip over any white space before the real string */ + buf++; + } - while (isspace(*buf)) - { - buf++; - } + if (*buf) + { /* Was a fieldwidth specified? */ @@ -559,6 +576,10 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) } } } + else + { + noassign = true; + } #endif } @@ -584,6 +605,11 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) } } } + else + { + /* None of the format specifiers matched */ + noassign = true; + } /* Note %n does not count as a conversion */ |