From bdcda65b1418114a65d76bfc3313c4afaf6840fa Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Mon, 17 Jan 2011 21:37:58 +0000 Subject: Fix cases where off_t (and APR_OFF_T_FMT) may be "larger" than int64 (and APR_INT64_T_FMT). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1060104 13f79535-47bb-0310-9956-ffa450edef68 --- strings/apr_snprintf.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'strings') diff --git a/strings/apr_snprintf.c b/strings/apr_snprintf.c index 013100799..695739480 100644 --- a/strings/apr_snprintf.c +++ b/strings/apr_snprintf.c @@ -810,10 +810,27 @@ APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *), adjust_precision = adjust_width = NO; /* - * Modifier check. Note that if APR_INT64_T_FMT is "d", - * the first if condition is never true. + * Modifier check. In same cases, APR_OFF_T_FMT can be + * "lld" and APR_INT64_T_FMT can be "ld" (that is, off_t is + * "larger" than int64). Check that case 1st. + * Note that if APR_OFF_T_FMT is "d", + * the first if condition is never true. If APR_INT64_T_FMT + * is "d' then the second if condition is never true. */ - if ((sizeof(APR_INT64_T_FMT) == 4 && + if ((sizeof(APR_OFF_T_FMT) > sizeof(APR_INT64_T_FMT)) && + (sizeof(APR_OFF_T_FMT) == 4 && + fmt[0] == APR_OFF_T_FMT[0] && + fmt[1] == APR_OFF_T_FMT[1]) || + (sizeof(APR_OFF_T_FMT) == 3 && + fmt[0] == APR_OFF_T_FMT[0]) || + (sizeof(APR_OFF_T_FMT) > 4 && + strncmp(fmt, APR_OFF_T_FMT, + sizeof(APR_OFF_T_FMT) - 2) == 0)) { + /* Need to account for trailing 'd' and null in sizeof() */ + var_type = IS_QUAD; + fmt += (sizeof(APR_OFF_T_FMT) - 2); + } + else if ((sizeof(APR_INT64_T_FMT) == 4 && fmt[0] == APR_INT64_T_FMT[0] && fmt[1] == APR_INT64_T_FMT[1]) || (sizeof(APR_INT64_T_FMT) == 3 && -- cgit v1.2.1