moriyoshi               Sat Feb 15 10:57:31 2003 EDT

  Added files:                 
    /php4/ext/standard/tests/strings    bug22227.phpt 

  Modified files:              
    /php4/ext/standard  formatted_print.c 
  Log:
  Fixed bug #22227
  Added test case for bug #22227
  
  
Index: php4/ext/standard/formatted_print.c
diff -u php4/ext/standard/formatted_print.c:1.64 
php4/ext/standard/formatted_print.c:1.65
--- php4/ext/standard/formatted_print.c:1.64    Thu Feb 13 12:25:31 2003
+++ php4/ext/standard/formatted_print.c Sat Feb 15 10:57:31 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: formatted_print.c,v 1.64 2003/02/13 17:25:31 iliaa Exp $ */
+/* $Id: formatted_print.c,v 1.65 2003/02/15 15:57:31 moriyoshi Exp $ */
 
 #include <math.h>                              /* modf() */
 #include "php.h"
@@ -158,12 +158,11 @@
                                                   int alignment, int len, int sign, 
int expprec)
 {
        register int npad;
+       int req_size;
+       int copy_len;
 
-       if (max_width && min_width) {
-               expprec = max_width = 0;        
-       }
-
-       npad = min_width - MIN(len, (expprec ? max_width : len));
+       copy_len = (expprec ? MIN(max_width, len) : len);
+       npad = min_width - copy_len;
 
        if (npad < 0) {
                npad = 0;
@@ -171,11 +170,11 @@
        
        PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n",
                                  *buffer, *pos, *size, add, min_width, padding, 
alignment));
-       if ((max_width == 0) && (! expprec)) {
-               max_width = MAX(min_width, len);
-       }
-       if ((*pos + max_width) >= *size) {
-               while ((*pos + max_width) >= *size) {
+
+       req_size = *pos + MAX(min_width, copy_len) + 1;
+
+       if (req_size > *size) {
+               while (req_size > *size) {
                        *size <<= 1;
                }
                PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size));
@@ -192,8 +191,8 @@
                }
        }
        PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add));
-       memcpy(&(*buffer)[*pos], add, MIN(max_width, len)+1);
-       *pos += MIN(max_width, len);
+       memcpy(&(*buffer)[*pos], add, copy_len + 1);
+       *pos += copy_len;
        if (alignment == ALIGN_LEFT) {
                while (npad--) {
                        (*buffer)[(*pos)++] = padding;

Index: php4/ext/standard/tests/strings/bug22227.phpt
+++ php4/ext/standard/tests/strings/bug22227.phpt
--TEST--
Bug #22227 (printf() field limiters broke between 4.2.3 and 4.3.0)
--FILE--
<?php
printf("%-3.3s", "abcdef");
print "\n";
?>
--EXPECT--
abc



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to