libs/libc/stdio/lib_libsscanf.c: Initialized the lastc pointer to avoid the checks for NULL. Removed a bug in the floating point parsing which allowed several signs after each other.

This commit is contained in:
Johannes 2019-02-14 15:43:21 -06:00 committed by Gregory Nutt
parent 69056d4053
commit 479363ae3b

View File

@ -276,6 +276,13 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
modifier = NO_MOD; modifier = NO_MOD;
ngetstart = obj->nget; /* for %n calculations */ ngetstart = obj->nget; /* for %n calculations */
/* Make sure lastc is not NULL. */
if (lastc == NULL)
{
lastc = &c;
}
/* Loop until all characters in the fmt string have been processed. We may /* Loop until all characters in the fmt string have been processed. We may
* have to continue loop after reaching the end the input data in order to * have to continue loop after reaching the end the input data in order to
* handle trailing %n format specifiers. * handle trailing %n format specifiers.
@ -470,11 +477,7 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
if (!fwidth) if (!fwidth)
{ {
if (lastc != NULL) *lastc = c;
{
*lastc = c;
}
return assigncount; return assigncount;
} }
@ -538,11 +541,7 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
if (fwidth != width) if (fwidth != width)
{ {
if (lastc != NULL) *lastc = c;
{
*lastc = c;
}
return assigncount; return assigncount;
} }
@ -875,11 +874,7 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
if (tmp == endptr || get_errno() == ERANGE) if (tmp == endptr || get_errno() == ERANGE)
{ {
if (lastc != NULL) *lastc = c;
{
*lastc = c;
}
return assigncount; return assigncount;
} }
@ -1027,6 +1022,7 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
if (!dot) if (!dot)
{ {
dot = true; dot = true;
sign = true;
} }
else else
{ {
@ -1049,6 +1045,10 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
{ {
stopconv = true; stopconv = true;
} }
else
{
sign = true;
}
if (!stopconv) if (!stopconv)
{ {
@ -1084,11 +1084,7 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
if (tmp == endptr || get_errno() == ERANGE) if (tmp == endptr || get_errno() == ERANGE)
{ {
if (lastc != NULL) *lastc = c;
{
*lastc = c;
}
return assigncount; return assigncount;
} }
@ -1235,10 +1231,6 @@ int lib_vsscanf(FAR struct lib_instream_s *obj, FAR int *lastc,
* matching failure or conversion. * matching failure or conversion.
*/ */
if (lastc != NULL) *lastc = c;
{
*lastc = c;
}
return (count || !conv) ? assigncount : EOF; return (count || !conv) ? assigncount : EOF;
} }