Merge pull request #226 from PX4/sscanf

Attempt to fix sscanf() %n handling
This commit is contained in:
Lorenz Meier 2013-03-17 02:43:24 -07:00
commit 39218d5fcc
1 changed files with 29 additions and 23 deletions

View File

@ -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 */