mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 10:46:28 +08:00
libc:Add macro restrictions to code that uses floating point numbers
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
@@ -174,7 +174,10 @@ doswitch:
|
||||
}
|
||||
|
||||
doexit:
|
||||
if (v) /* Default => accept */
|
||||
|
||||
/* Default => accept */
|
||||
|
||||
if (v)
|
||||
{
|
||||
for (i = 0; i < 32; i++) /* Invert all */
|
||||
{
|
||||
@@ -950,7 +953,10 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
FAR double *pd = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_FLOAT
|
||||
FAR float *pf = NULL;
|
||||
#endif
|
||||
|
||||
linfo("Performing floating point conversion\n");
|
||||
|
||||
@@ -973,10 +979,12 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_FLOAT
|
||||
{
|
||||
pf = va_arg(ap, FAR float *);
|
||||
*pf = 0.0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIBC_FLOATINGPOINT
|
||||
@@ -994,7 +1002,9 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
# if defined(CONFIG_HAVE_DOUBLE) || defined(CONFIG_HAVE_FLOAT)
|
||||
FAR char *endptr;
|
||||
# endif
|
||||
bool expnt;
|
||||
bool dot;
|
||||
bool sign;
|
||||
@@ -1003,8 +1013,9 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
# ifdef CONFIG_HAVE_DOUBLE
|
||||
double dvalue;
|
||||
# endif
|
||||
# ifdef CONFIG_HAVE_FLOAT
|
||||
float fvalue;
|
||||
|
||||
# endif
|
||||
/* Was a fieldwidth specified? */
|
||||
|
||||
if (!width || width > sizeof(tmp) - 1)
|
||||
@@ -1093,17 +1104,21 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
}
|
||||
else
|
||||
# endif
|
||||
# ifdef CONFIG_HAVE_FLOAT
|
||||
{
|
||||
fvalue = strtof(tmp, &endptr);
|
||||
}
|
||||
# endif
|
||||
|
||||
/* Check if the number was successfully converted */
|
||||
|
||||
# if defined(CONFIG_HAVE_DOUBLE) || defined(CONFIG_HAVE_FLOAT)
|
||||
if (tmp == endptr || get_errno() == ERANGE)
|
||||
{
|
||||
*lastc = c;
|
||||
return assigncount;
|
||||
}
|
||||
#endif
|
||||
|
||||
set_errno(errsave);
|
||||
|
||||
@@ -1126,8 +1141,10 @@ int lib_vscanf(FAR struct lib_instream_s *stream, FAR int *lastc,
|
||||
{
|
||||
/* Return the float value */
|
||||
|
||||
# ifdef CONFIG_HAVE_FLOAT
|
||||
linfo("Return %f to %p\n", (double)fvalue, pf);
|
||||
*pf = fvalue;
|
||||
# endif
|
||||
}
|
||||
|
||||
assigncount++;
|
||||
|
||||
@@ -131,7 +131,9 @@ struct arg_s
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
unsigned long long ull;
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
double d;
|
||||
#endif
|
||||
FAR char *cp;
|
||||
} value;
|
||||
};
|
||||
@@ -1350,9 +1352,11 @@ int lib_vsprintf(FAR struct lib_outstream_s *stream,
|
||||
arglist[i].value.u = va_arg(ap, unsigned int);
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
case TYPE_DOUBLE:
|
||||
arglist[i].value.d = va_arg(ap, double);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case TYPE_CHAR_POINTER:
|
||||
arglist[i].value.cp = va_arg(ap, FAR char *);
|
||||
|
||||
Reference in New Issue
Block a user