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
This commit is contained in:
patacongo
2012-09-21 22:05:41 +00:00
parent 4a5f639e22
commit 6052cd078a
+40 -14
View File
@@ -38,9 +38,11 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <debug.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 *bufstart;
FAR char *tv; FAR char *tv;
FAR const char *tc; FAR const char *tc;
bool lflag;
bool noassign;
int count; int count;
int noassign;
int width; int width;
int base = 10; int base = 10;
int lflag;
char tmp[MAXLN]; char tmp[MAXLN];
lvdbg("vsscanf: buf=\"%s\" fmt=\"%s\"\n", buf, fmt); 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 */ /* Parse the format, extracting values from the input buffer as needed */
count = 0; count = 0;
noassign = 0;
width = 0; width = 0;
lflag = 0; noassign = false;
lflag = false;
while (*fmt && *buf) while (*fmt && *buf)
{ {
@@ -223,11 +225,13 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap)
if (*fmt == '*') if (*fmt == '*')
{ {
noassign = 1; noassign = true;
} }
else if (*fmt == 'l' || *fmt == 'L') else if (*fmt == 'l' || *fmt == 'L')
{ {
lflag = 1; /* NOTE: Missing check for long long ('ll') */
lflag = true;
} }
else if (*fmt >= '1' && *fmt <= '9') else if (*fmt >= '1' && *fmt <= '9')
{ {
@@ -349,15 +353,24 @@ int vsscanf(FAR char *buf, FAR const char *fmt, va_list ap)
buf += width; buf += width;
if (!noassign) if (!noassign)
{ {
int *pint = va_arg(ap, int*);
#ifdef SDCC #ifdef SDCC
char *endptr; char *endptr;
int tmpint = strtol(tmp, &endptr, base); long tmplong = strtol(tmp, &endptr, base);
#else #else
int tmpint = strtol(tmp, NULL, base); long tmplong = strtol(tmp, NULL, base);
#endif #endif
lvdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint); if (lflag)
*pint = tmpint; {
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) if (!noassign)
{ {
int *pint = va_arg(ap, int*); size_t nchars = (size_t)(buf - bufstart);
*pint = (int)(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++; count++;
} }
width = noassign = lflag = 0; width = 0;
noassign = false;
lflag = false;
fmt++; fmt++;
} }