From 332a99efde2c153ae2c8a22b6b1b690e4a3a8d6e Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Fri, 27 Dec 2024 15:25:14 +0100 Subject: [PATCH] fix --disable-float-exp tests --- src/str/vsnprintf_s.c | 24 ++++++++++++------------ tests/test_vsnprintf_s.c | 2 +- tests/test_vsprintf_s.c | 4 ++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/str/vsnprintf_s.c b/src/str/vsnprintf_s.c index 20e9f60c..b847f0fd 100644 --- a/src/str/vsnprintf_s.c +++ b/src/str/vsnprintf_s.c @@ -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 #include #endif @@ -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, @@ -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, @@ -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, @@ -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); @@ -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, @@ -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, @@ -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') @@ -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': @@ -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, @@ -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++; diff --git a/tests/test_vsnprintf_s.c b/tests/test_vsnprintf_s.c index accfd2a9..5fcd9051 100644 --- a/tests/test_vsnprintf_s.c +++ b/tests/test_vsnprintf_s.c @@ -1,7 +1,7 @@ /*------------------------------------------------------------------ * test_vsnprintf_s * File 'wchar/vsnprintf_s.c' - * Lines executed:78.62% of 608 + * Lines executed:78.70% of 615 * *------------------------------------------------------------------ */ diff --git a/tests/test_vsprintf_s.c b/tests/test_vsprintf_s.c index 6ba8f8fb..755b8916 100644 --- a/tests/test_vsprintf_s.c +++ b/tests/test_vsprintf_s.c @@ -327,12 +327,14 @@ 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() @@ -340,12 +342,14 @@ int test_vsprintf_s(void) { 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 {