helly           Mon Aug 11 16:14:25 2003 EDT

  Added files:                 
    /php-src/ext/standard/tests/array   bug21918.phpt 

  Modified files:              
    /ZendEngine2        zend_hash.c zend_hash.h 
  Log:
  Bugfix 21918
  
Index: ZendEngine2/zend_hash.c
diff -u ZendEngine2/zend_hash.c:1.109 ZendEngine2/zend_hash.c:1.110
--- ZendEngine2/zend_hash.c:1.109       Thu Jul 31 01:08:59 2003
+++ ZendEngine2/zend_hash.c     Mon Aug 11 16:14:25 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_hash.c,v 1.109 2003/07/31 05:08:59 andi Exp $ */
+/* $Id: zend_hash.c,v 1.110 2003/08/11 20:14:25 helly Exp $ */
 
 #include "zend.h"
 
@@ -364,7 +364,7 @@
                        }
                        UPDATE_DATA(ht, p, pData, nDataSize);
                        HANDLE_UNBLOCK_INTERRUPTIONS();
-                       if ((long)h >= (long)ht->nNextFreeElement) {
+                       if ((long)h >= (long)ht->nNextFreeElement || 
!ht->nNumOfElements) {
                                ht->nNextFreeElement = h + 1;
                        }
                        if (pDest) {
@@ -392,7 +392,7 @@
        CONNECT_TO_GLOBAL_DLLIST(p, ht);
        HANDLE_UNBLOCK_INTERRUPTIONS();
 
-       if ((long)h >= (long)ht->nNextFreeElement) {
+       if ((long)h >= (long)ht->nNextFreeElement || !ht->nNumOfElements) {
                ht->nNextFreeElement = h + 1;
        }
        ht->nNumOfElements++;
Index: ZendEngine2/zend_hash.h
diff -u ZendEngine2/zend_hash.h:1.72 ZendEngine2/zend_hash.h:1.73
--- ZendEngine2/zend_hash.h:1.72        Wed Jul 23 04:56:34 2003
+++ ZendEngine2/zend_hash.h     Mon Aug 11 16:14:25 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_hash.h,v 1.72 2003/07/23 08:56:34 zeev Exp $ */
+/* $Id: zend_hash.h,v 1.73 2003/08/11 20:14:25 helly Exp $ */
 
 #ifndef ZEND_HASH_H
 #define ZEND_HASH_H
@@ -287,8 +287,11 @@
 #define HANDLE_NUMERIC(key, length, func) {                                           
                                                 \
        register char *tmp=key;                                                        
                                                                 \
                                                                                       
                                                                                       
  \
+       if (*tmp=='-') {                                                               
                                                                         \
+               tmp++;                                                                 
                                                                                 \
+       }                                                                              
                                                                                       
  \
        if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index */              
                         \
-               char *end=tmp+length-1;                                                
                                                                 \
+               char *end=key+length-1;                                                
                                                                 \
                ulong idx;                                                             
                                                                                 \
                                                                                       
                                                                                       
  \
                if (*tmp++=='0' && length>2) { /* don't accept numbers with leading 
zeros */    \
@@ -301,9 +304,16 @@
                        tmp++;                                                         
                                                                                 \
                }                                                                      
                                                                                       
  \
                if (tmp==end && *tmp=='\0') { /* a numeric index */                    
                                         \
-                       idx = strtol(key, NULL, 10);                                   
                                                         \
-                       if (idx!=LONG_MAX) {                                           
                                                                 \
-                               return func;                                           
                                                                         \
+                       if (*key=='-') {                                               
                                                                         \
+                               idx = strtol(key, NULL, 10);                           
                                                         \
+                               if (idx!=LONG_MIN) {                                   
                                                                 \
+                                       return func;                                   
                                                                         \
+                               }                                                      
                                                                                       
  \
+                       } else {                                                       
                                                                                 \
+                               idx = strtol(key, NULL, 10);                           
                                                         \
+                               if (idx!=LONG_MAX) {                                   
                                                                 \
+                                       return func;                                   
                                                                         \
+                               }                                                      
                                                                                       
  \
                        }                                                              
                                                                                       
  \
                }                                                                      
                                                                                       
  \
        } while (0);                                                                   
                                                                         \

Index: php-src/ext/standard/tests/array/bug21918.phpt
+++ php-src/ext/standard/tests/array/bug21918.phpt
--TEST--
--FILE--
<?php

echo "==Mixed==\n";
$a = array(-1=>'a', '-2'=>'b', 3=>'c', '4'=>'d', 5=>'e', '6001'=>'f', '07'=>'g');

foreach($a as $k => $v) {
        var_dump($k);
        var_dump($v);
}

echo "==Normal==\n";
$b = array();
$b[] = 'a';

foreach($b as $k => $v) {
        var_dump($k);
        var_dump($v);
}

echo "==Negative==\n";
$c = array('-2' => 'a');
$c[] = 'b';

foreach($c as $k => $v) {
        var_dump($k);
        var_dump($v);
}

echo "==Done==\n";
?>
--EXPECT--
==Mixed==
int(-1)
string(1) "a"
int(-2)
string(1) "b"
int(3)
string(1) "c"
int(4)
string(1) "d"
int(5)
string(1) "e"
int(6001)
string(1) "f"
string(2) "07"
string(1) "g"
==Normal==
int(0)
string(1) "a"
==Negative==
int(-2)
string(1) "a"
int(-1)
string(1) "b"
==Done==



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

Reply via email to