apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r267459 - /apr/apr/trunk/strings/apr_snprintf.c
Date Sat, 03 Sep 2005 14:01:53 GMT
Author: wrowe
Date: Sat Sep  3 07:01:49 2005
New Revision: 267459

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

  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/trunk/strings/apr_snprintf.c

Modified: apr/apr/trunk/strings/apr_snprintf.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/strings/apr_snprintf.c?rev=267459&r1=267458&r2=267459&view=diff
==============================================================================
--- apr/apr/trunk/strings/apr_snprintf.c (original)
+++ apr/apr/trunk/strings/apr_snprintf.c Sat Sep  3 07:01:49 2005
@@ -290,7 +290,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';                             \
@@ -703,8 +704,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;
@@ -784,13 +785,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;
@@ -805,10 +808,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