From a7bc6a6eb219b69dd32e3926d84d5610f59d7181 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 16 Sep 2017 09:16:15 +0000 Subject: [PATCH] fixed some bugs in formatting output function --- qse/include/qse/types.h | 2 +- qse/lib/cmn/fmt-out.h | 48 ++++++++++++++++++++++++++++++++++------- qse/samples/si/log01.c | 1 + 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/qse/include/qse/types.h b/qse/include/qse/types.h index c46f9901..1d76c90d 100644 --- a/qse/include/qse/types.h +++ b/qse/include/qse/types.h @@ -204,7 +204,7 @@ typedef enum qse_bool_t qse_bool_t; typedef __uint8_t qse_uint8_t; #endif -#ifdef QSE_HAVE_INT8_T +#if defined(QSE_HAVE_INT8_T) # define QSE_SIZEOF_INT8_T 1 # define QSE_SIZEOF_UINT8_T 1 # undef QSE_SIZEOF_INTMAX_T diff --git a/qse/lib/cmn/fmt-out.h b/qse/lib/cmn/fmt-out.h index 6b378956..762a0857 100644 --- a/qse/lib/cmn/fmt-out.h +++ b/qse/lib/cmn/fmt-out.h @@ -361,7 +361,7 @@ reswitch: if (flagc & FLAGC_LENMOD) { /* conflict with other length modifier */ - save_lm_flag = lm_flag; + lm_flag = save_lm_flag; goto invalid_format; } flagc |= FLAGC_LENMOD; @@ -841,37 +841,53 @@ reswitch: num = (unsigned char)va_arg (ap, int); else if (lm_flag & LF_I8) - #if (QSE_SIZEOF_UINT8_T < QSE_SIZEOF_UINT) + { + #if (QSE_SIZEOF_UINT8_T < QSE_SIZEOF_INT) num = (qse_uint8_t)va_arg (ap, unsigned int); #else num = va_arg (ap, qse_uint8_t); #endif + } else if (lm_flag & LF_I16) - #if (QSE_SIZEOF_UINT16_T < QSE_SIZEOF_UINT) + { + #if (QSE_SIZEOF_UINT16_T < QSE_SIZEOF_INT) num = (qse_uint16_t)va_arg (ap, unsigned int); #else num = va_arg (ap, qse_uint16_t); #endif + } else if (lm_flag & LF_I32) - #if (QSE_SIZEOF_UINT32_T < QSE_SIZEOF_UINT) + { + #if (QSE_SIZEOF_UINT32_T < QSE_SIZEOF_INT) num = (qse_uint32_t)va_arg (ap, unsigned int); #else num = va_arg (ap, qse_uint32_t); #endif + } + #if defined(QSE_HAVE_UINT64_T) else if (lm_flag & LF_I64) - #if defined(QSE_HAVE_UINT64_T) && (QSE_SIZEOF_UINT64_T < QSE_SIZEOF_UINT) + { + #if (QSE_SIZEOF_UINT64_T < QSE_SIZEOF_INT) num = (qse_uint64_t)va_arg (ap, unsigned int); #else num = va_arg (ap, qse_uint64_t); #endif + } + #endif + #if defined(QSE_HAVE_UINT128_T) else if (lm_flag & LF_I128) - #if defined(QSE_HAVE_UINT128_T) && (QSE_SIZEOF_UINT128_T < QSE_SIZEOF_UINT) + { + #if (QSE_SIZEOF_UINT128_T < QSE_SIZEOF_INT) num = (qse_uint128_t)va_arg (ap, unsigned int); #else num = va_arg (ap, qse_uint128_t); #endif + } + #endif else + { num = va_arg (ap, unsigned int); + } goto number; handle_sign: @@ -915,37 +931,53 @@ handle_sign: num = (char)va_arg (ap, int); else if (lm_flag & LF_I8) + { #if (QSE_SIZEOF_INT8_T < QSE_SIZEOF_INT) num = (qse_int8_t)va_arg (ap, int); #else num = va_arg (ap, qse_int8_t); #endif + } else if (lm_flag & LF_I16) + { #if (QSE_SIZEOF_INT16_T < QSE_SIZEOF_INT) num = (qse_int16_t)va_arg (ap, int); #else num = va_arg (ap, qse_int16_t); #endif + } else if (lm_flag & LF_I32) + { #if (QSE_SIZEOF_INT32_T < QSE_SIZEOF_INT) num = (qse_int32_t)va_arg (ap, int); #else num = va_arg (ap, qse_int32_t); #endif + } + #if defined(QSE_HAVE_INT64_T) else if (lm_flag & LF_I64) - #if defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_INT64_T < QSE_SIZEOF_INT) + { + #if (QSE_SIZEOF_INT64_T < QSE_SIZEOF_INT) num = (qse_int64_t)va_arg (ap, int); #else num = va_arg (ap, qse_int64_t); #endif + } + #endif + #if defined(QSE_HAVE_INT128_T) else if (lm_flag & LF_I128) - #if defined(QSE_HAVE_INT128_T) && (QSE_SIZEOF_INT128_T < QSE_SIZEOF_INT) + { + #if (QSE_SIZEOF_INT128_T < QSE_SIZEOF_INT) num = (qse_int128_t)va_arg (ap, int); #else num = va_arg (ap, qse_int128_t); #endif + } + #endif else + { num = va_arg (ap, int); + } number: if (sign && (qse_intmax_t)num < 0) diff --git a/qse/samples/si/log01.c b/qse/samples/si/log01.c index 9516e74a..aa66dbb2 100644 --- a/qse/samples/si/log01.c +++ b/qse/samples/si/log01.c @@ -14,6 +14,7 @@ void t1 (void) t.file = QSE_T("/tmp/t3.log"); /*qse_strtonwad ("127.0.0.1:514", &nwad);*/ + /*qse_strtonwad ("@/var/run/log", &nwad);*/ qse_strtonwad ("@/dev/log", &nwad); qse_nwadtoskad (&nwad, &t.syslog_remote);