apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r279647 - /apr/apr/branches/1.2.x/strings/apr_snprintf.c
Date Thu, 08 Sep 2005 21:40:41 GMT
Author: wrowe
Date: Thu Sep  8 14:40:38 2005
New Revision: 279647

URL: http://svn.apache.org/viewcvs?rev=279647&view=rev
Log:

  Backport rev 267459

  Fix multiple sign'edness issues;  for %width.prec variables, neither
  is -ever- signed, we pull out -width as a flag, and prec is folded +.
  Changing the code only required special handling of %*.* variables,
  continuing to read them as int, and preserving the folding of negative
  values that's already there.


Modified:
    apr/apr/branches/1.2.x/strings/apr_snprintf.c

Modified: apr/apr/branches/1.2.x/strings/apr_snprintf.c
URL: http://svn.apache.org/viewcvs/apr/apr/branches/1.2.x/strings/apr_snprintf.c?rev=279647&r1=279646&r2=279647&view=diff
==============================================================================
--- apr/apr/branches/1.2.x/strings/apr_snprintf.c (original)
+++ apr/apr/branches/1.2.x/strings/apr_snprintf.c Thu Sep  8 14:40:38 2005
@@ -289,7 +289,8 @@
  */
 #define FIX_PRECISION(adjust, precision, s, s_len)  \
     if (adjust) {                                   \
-        int p = precision < NUM_BUF_SIZE - 1 ? precision : NUM_BUF_SIZE - 1; \
+        apr_size_t p = (precision + 1 < NUM_BUF_SIZE) \
+                     ? precision : NUM_BUF_SIZE - 1;  \
         while (s_len < p)                           \
         {                                           \
             *--s = '0';                             \
@@ -702,8 +703,8 @@
     char *q;
     apr_size_t s_len;
 
-    register int min_width = 0;
-    int precision = 0;
+    register apr_size_t min_width = 0;
+    apr_size_t precision = 0;
     enum {
         LEFT, RIGHT
     } adjust;
@@ -783,13 +784,15 @@
                     adjust_width = YES;
                 }
                 else if (*fmt == '*') {
-                    min_width = va_arg(ap, int);
+                    int v = va_arg(ap, int);
                     fmt++;
                     adjust_width = YES;
-                    if (min_width < 0) {
+                    if (v < 0) {
                         adjust = LEFT;
-                        min_width = -min_width;
+                        min_width = (apr_size_t)(-v);
                     }
+                    else
+                        min_width = (apr_size_t)v;
                 }
                 else
                     adjust_width = NO;
@@ -804,10 +807,9 @@
                         STR_TO_DEC(fmt, precision);
                     }
                     else if (*fmt == '*') {
-                        precision = va_arg(ap, int);
+                        int v = va_arg(ap, int);
                         fmt++;
-                        if (precision < 0)
-                            precision = 0;
+                        precision = (v < 0) ? 0 : (apr_size_t)v;
                     }
                     else
                         precision = 0;



Mime
View raw message