diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-09-21 22:05:41 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-09-21 22:05:41 +0000 |
commit | 6052cd078a07e5f3c4f7481537f2b17c48d32d98 (patch) | |
tree | fcd89a59d59dbcf5cb6f4f05c25fafd6db38dfc3 /nuttx/lib | |
parent | 4a5f639e222c25405bbe0c381d7aa0880029761a (diff) | |
download | px4-firmware-6052cd078a07e5f3c4f7481537f2b17c48d32d98.tar.gz px4-firmware-6052cd078a07e5f3c4f7481537f2b17c48d32d98.tar.bz2 px4-firmware-6052cd078a07e5f3c4f7481537f2b17c48d32d98.zip |
More sscanf: Long flag (as in %ld) not be used in all of the places it should be
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5172 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/stdio/lib_sscanf.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/nuttx/lib/stdio/lib_sscanf.c b/nuttx/lib/stdio/lib_sscanf.c index 032164ba1..7e1fae276 100644 --- a/nuttx/lib/stdio/lib_sscanf.c +++ b/nuttx/lib/stdio/lib_sscanf.c @@ -38,9 +38,11 @@ ****************************************************************************/ #include <nuttx/compiler.h> + #include <sys/types.h> #include <stdarg.h> #include <stdlib.h> +#include <stdbool.h> #include <string.h> #include <ctype.h> #include <debug.h> @@ -173,11 +175,11 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) FAR char *bufstart; FAR char *tv; FAR const char *tc; + bool lflag; + bool noassign; int count; - int noassign; int width; int base = 10; - int lflag; char tmp[MAXLN]; lvdbg("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt); @@ -191,9 +193,9 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) /* Parse the format, extracting values from the input buffer as needed */ count = 0; - noassign = 0; width = 0; - lflag = 0; + noassign = false; + lflag = false; while (*fmt && *buf) { @@ -223,11 +225,13 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) if (*fmt == '*') { - noassign = 1; + noassign = true; } else if (*fmt == 'l' || *fmt == 'L') { - lflag = 1; + /* NOTE: Missing check for long long ('ll') */ + + lflag = true; } else if (*fmt >= '1' && *fmt <= '9') { @@ -349,15 +353,24 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) buf += width; if (!noassign) { - int *pint = va_arg(ap, int*); #ifdef SDCC char *endptr; - int tmpint = strtol(tmp, &endptr, base); + long tmplong = strtol(tmp, &endptr, base); #else - int tmpint = strtol(tmp, NULL, base); + long tmplong = strtol(tmp, NULL, base); #endif - lvdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint); - *pint = tmpint; + if (lflag) + { + long *plong = va_arg(ap, long*); + lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, plong); + *plong = tmplong; + } + else + { + int *pint = va_arg(ap, int*); + lvdbg("vsscanf: Return %ld to 0x%p\n", tmplong, pint); + *pint = (int)tmplong; + } } } @@ -440,8 +453,18 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) if (!noassign) { - int *pint = va_arg(ap, int*); - *pint = (int)(buf - bufstart); + 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; + } } } @@ -452,7 +475,10 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap) count++; } - width = noassign = lflag = 0; + width = 0; + noassign = false; + lflag = false; + fmt++; } |