Skip to content

Commit

Permalink
fix --disable-float-exp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Dec 27, 2024
1 parent 5cdef98 commit 332a99e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/str/vsnprintf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
#define FLAGS_LONG_DOUBLE (1U << 12U)

// import float.h for DBL_MAX, math.h for isinf()
#if defined(PRINTF_SUPPORT_FLOAT)
#ifdef PRINTF_SUPPORT_FLOAT
#include <float.h>
#include <math.h>
#endif
Expand Down Expand Up @@ -363,9 +363,9 @@ static size_t safec_ntoa_long_long(out_fct_type out, const char *funcname,
}
#endif // PRINTF_SUPPORT_LONG_LONG

#if defined(PRINTF_SUPPORT_FLOAT)
#ifdef PRINTF_SUPPORT_FLOAT

#if defined(PRINTF_SUPPORT_EXPONENTIAL)
#ifdef PRINTF_SUPPORT_EXPONENTIAL
// forward declaration so that safec_ftoa can switch to exp notation for values
// > PRINTF_MAX_FLOAT
static size_t safec_etoa(out_fct_type out, const char *funcname, char *buffer,
Expand Down Expand Up @@ -431,7 +431,7 @@ static size_t safec_ftoa(out_fct_type out, const char *funcname, char *buffer,
// standard printf behavior is to print EVERY whole number digit -- which
// could be 100s of characters overflowing your buffers == bad
if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
#ifdef PRINTF_SUPPORT_EXPONENTIAL
#ifdef PRINTF_SUPPORT_LONG_DOUBLE
// TODO Is %le good?
return safec_etoa_long(out, funcname, buffer, idx, maxlen,
Expand Down Expand Up @@ -671,7 +671,7 @@ static inline size_t safec_atoa_long(out_fct_type out, const char *funcname,
}
#endif

#if defined(PRINTF_SUPPORT_EXPONENTIAL)
#ifdef PRINTF_SUPPORT_EXPONENTIAL
// the complete same as safec_ftoa_long, but taking double, not long double
static inline size_t safec_atoa(out_fct_type out, const char *funcname,
char *buffer, size_t idx, size_t maxlen,
Expand Down Expand Up @@ -972,7 +972,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
format++;
}
break;
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
#ifdef PRINTF_SUPPORT_PTRDIFF_T
case 't':
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG
: FLAGS_LONG_LONG);
Expand Down Expand Up @@ -1042,7 +1042,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
if ((*format == 'i') || (*format == 'd')) {
// signed
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
#ifdef PRINTF_SUPPORT_LONG_LONG
const long long value = va_arg(va, long long);
idx = safec_ntoa_long_long(
out, funcname, buffer, idx, bufsize,
Expand All @@ -1068,7 +1068,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
} else {
// unsigned
if (flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG)
#ifdef PRINTF_SUPPORT_LONG_LONG
idx = safec_ntoa_long_long(
out, funcname, buffer, idx, bufsize,
va_arg(va, unsigned long long), false, base, precision,
Expand All @@ -1093,7 +1093,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
format++;
break;
}
#if defined(PRINTF_SUPPORT_FLOAT)
#ifdef PRINTF_SUPPORT_FLOAT
case 'f':
case 'F':
if (*format == 'F')
Expand Down Expand Up @@ -1122,7 +1122,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
va_arg(va, double), precision, width, flags);
}
break;
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
#ifdef PRINTF_SUPPORT_EXPONENTIAL
case 'e':
case 'E':
case 'g':
Expand Down Expand Up @@ -1355,7 +1355,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
uintptr_t arg = (uintptr_t)va_arg(va, void *);
width = sizeof(void *) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
#if defined(PRINTF_SUPPORT_LONG_LONG)
#ifdef PRINTF_SUPPORT_LONG_LONG
if (sizeof(uintptr_t) == sizeof(long long)) {
idx = safec_ntoa_long_long(out, funcname, buffer, idx, bufsize,
arg, false, 16U, precision, width,
Expand All @@ -1365,7 +1365,7 @@ int safec_vsnprintf_s(out_fct_type out, const char *funcname, char *buffer,
idx = safec_ntoa_long(out, funcname, buffer, idx, bufsize,
(unsigned long)arg, false, 16U, precision,
width, flags);
#if defined(PRINTF_SUPPORT_LONG_LONG)
#ifdef PRINTF_SUPPORT_LONG_LONG
}
#endif
format++;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_vsnprintf_s.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*------------------------------------------------------------------
* test_vsnprintf_s
* File 'wchar/vsnprintf_s.c'
* Lines executed:78.62% of 608
* Lines executed:78.70% of 615
*
*------------------------------------------------------------------
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/test_vsprintf_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,25 +327,29 @@ int test_vsprintf_s(void) {
rc = vtprintf_s(str1, LEN, "%llf", 0.0);
NOERR()
EXPSTR(str1, "0.000000");
#ifdef PRINTF_SUPPORT_EXPONENTIAL
rc = vtprintf_s(str1, LEN, "%a", 0.0);
NOERR()
EXPSTR(str1, "0x0p+0");
rc = vtprintf_s(str1, LEN, "%A", 0.0);
NOERR()
EXPSTR(str1, "0X0P+0");
#endif
#ifdef PRINTF_SUPPORT_LONG_DOUBLE
rc = vtprintf_s(str1, LEN, "%Lf", 0.0L);
NOERR()
EXPSTR(str1, "0.000000");
rc = vtprintf_s(str1, LEN, "long >%Lf<", 0.0L);
NOERR()
EXPSTR(str1, "long >0.000000<");
#ifdef PRINTF_SUPPORT_EXPONENTIAL
rc = vtprintf_s(str1, LEN, "long >%La<", 0.0L);
NOERR()
EXPSTR(str1, "long >0x0p+0<");
rc = vtprintf_s(str1, LEN, "long >%LA<", 0.0L);
NOERR()
EXPSTR(str1, "long >0X0P+0<");
#endif
#endif

{
Expand Down

0 comments on commit 332a99e

Please sign in to comment.