diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-03-16 20:05:22 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-03-16 20:05:22 +0100 |
commit | 2d47816e558388191f4294dee469a0a224e8bb40 (patch) | |
tree | 05448d5777444f3f4da1e0c414ca359f3ae9bae2 | |
parent | 6b947a67d07eadc7dc882edf4505377085979784 (diff) | |
download | px4-firmware-2d47816e558388191f4294dee469a0a224e8bb40.tar.gz px4-firmware-2d47816e558388191f4294dee469a0a224e8bb40.tar.bz2 px4-firmware-2d47816e558388191f4294dee469a0a224e8bb40.zip |
Attempt to fix sscanf() %n handling
-rw-r--r-- | nuttx/libc/stdio/lib_sscanf.c | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/nuttx/libc/stdio/lib_sscanf.c b/nuttx/libc/stdio/lib_sscanf.c index 77a6cf212..0092fbec2 100644 --- a/nuttx/libc/stdio/lib_sscanf.c +++ b/nuttx/libc/stdio/lib_sscanf.c @@ -197,7 +197,7 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) noassign = false; lflag = false; - while (*fmt && *buf) + while (*fmt) { /* Skip over white space */ @@ -242,6 +242,33 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) fmt--; } } + + /* Process %n: Character count */ + + if (*fmt == 'n') + { + lvdbg("vsscanf: Performing character count\n"); + + if (!noassign) + { + size_t nchars = (size_t)(buf - bufstart); + + if (lflag) + { + long *plong = va_arg(ap, long*); + *plong = (long)nchars; + } + else + { + int *pint = va_arg(ap, int*); + *pint = (int)nchars; + } + } + } else { + + /* Check for valid data in input string */ + if (!(*buf)) + break; /* Process %s: String conversion */ @@ -445,28 +472,7 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) #endif } - /* Process %n: Character count */ - - else if (*fmt == 'n') - { - lvdbg("vsscanf: Performing character count\n"); - - if (!noassign) - { - size_t nchars = (size_t)(buf - bufstart); - - if (lflag) - { - long *plong = va_arg(ap, long*); - *plong = (long)nchars; - } - else - { - int *pint = va_arg(ap, int*); - *pint = (int)nchars; - } - } - } + } /* Note %n does not count as a conversion */ |