libc: scanf, printf %z change switch const to if
switch const will cause a switch_selector_expr_is_constant warning catched by coverity. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
parent
f5de966471
commit
7445c97c77
@ -317,33 +317,33 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
|||||||
}
|
}
|
||||||
else if (fmt_char(fmt) == 'z')
|
else if (fmt_char(fmt) == 'z')
|
||||||
{
|
{
|
||||||
switch (sizeof(size_t))
|
if (sizeof(size_t) == sizeof(unsigned short))
|
||||||
{
|
{
|
||||||
/* The only known cases that the default will be hit are
|
modifier = H_MOD;
|
||||||
* (1) the eZ80 which has sizeof(size_t) = 3 which is the
|
}
|
||||||
* same as the sizeof(int). And (2) if
|
else if (sizeof(size_t) == sizeof(unsigned long))
|
||||||
|
{
|
||||||
|
modifier = L_MOD;
|
||||||
|
}
|
||||||
|
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
|
||||||
|
else if (sizeof(size_t) == sizeof(unsigned long long))
|
||||||
|
{
|
||||||
|
modifier = LL_MOD;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* The only known cases that the default will be hit
|
||||||
|
* are (1) the eZ80 which has sizeof(size_t) = 3 which
|
||||||
|
* is the same as the sizeof(int). And (2) if
|
||||||
* CONFIG_HAVE_LONG_LONG
|
* CONFIG_HAVE_LONG_LONG
|
||||||
* is not enabled and sizeof(size_t) is equal to
|
* is not enabled and sizeof(size_t) is equal to
|
||||||
* sizeof(unsigned long long). This latter case is an
|
* sizeof(unsigned long long). This latter case is an
|
||||||
* error.
|
* error.
|
||||||
|
* Treat as integer with no size qualifier.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
default:
|
continue;
|
||||||
continue; /* Treat as integer with no size qualifier. */
|
|
||||||
|
|
||||||
case sizeof(unsigned short):
|
|
||||||
modifier = H_MOD;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case sizeof(unsigned long):
|
|
||||||
modifier = L_MOD;
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
|
|
||||||
case sizeof(unsigned long long):
|
|
||||||
modifier = LL_MOD;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fmt_char(fmt) == 'j')
|
else if (fmt_char(fmt) == 'j')
|
||||||
|
@ -389,7 +389,23 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
|
|||||||
|
|
||||||
if (c == 'z' || c == 't')
|
if (c == 'z' || c == 't')
|
||||||
{
|
{
|
||||||
switch (sizeof(size_t))
|
if (sizeof(size_t) == sizeof(unsigned short))
|
||||||
|
{
|
||||||
|
c = 'h';
|
||||||
|
}
|
||||||
|
else if (sizeof(size_t) == sizeof(unsigned long))
|
||||||
|
{
|
||||||
|
c = 'l';
|
||||||
|
}
|
||||||
|
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
|
||||||
|
else if (sizeof(size_t) == sizeof(unsigned long long))
|
||||||
|
{
|
||||||
|
c = 'l';
|
||||||
|
flags |= FL_LONG;
|
||||||
|
flags &= ~FL_SHORT;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
{
|
{
|
||||||
/* The only known cases that the default will be hit are
|
/* The only known cases that the default will be hit are
|
||||||
* (1) the eZ80 which has sizeof(size_t) = 3 which is the
|
* (1) the eZ80 which has sizeof(size_t) = 3 which is the
|
||||||
@ -398,26 +414,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
|
|||||||
* is not enabled and sizeof(size_t) is equal to
|
* is not enabled and sizeof(size_t) is equal to
|
||||||
* sizeof(unsigned long long). This latter case is an
|
* sizeof(unsigned long long). This latter case is an
|
||||||
* error.
|
* error.
|
||||||
|
* Treat as integer with no size qualifier.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
default:
|
continue;
|
||||||
continue; /* Treat as integer with no size qualifier. */
|
|
||||||
|
|
||||||
case sizeof(unsigned short):
|
|
||||||
c = 'h';
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if defined(CONFIG_HAVE_LONG_LONG) && ULLONG_MAX != ULONG_MAX
|
|
||||||
case sizeof(unsigned long long):
|
|
||||||
c = 'l';
|
|
||||||
flags |= FL_LONG;
|
|
||||||
flags &= ~FL_SHORT;
|
|
||||||
break;
|
|
||||||
#else
|
|
||||||
case sizeof(unsigned long):
|
|
||||||
c = 'l';
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user