Just a notice:

The third optional parameter is not suggested in the branch.
Therefore I won't try to merge this patch to PHP_4_3, but due to this 
decision the behaviour of the function slightly differs one another in the 
cases like range("A", "Ä");

Moriyoshi

"Moriyoshi Koizumi" <[EMAIL PROTECTED]> wrote:

> moriyoshi             Sat Nov 23 06:27:56 2002 EDT
> 
>   Modified files:              
>     /php4/ext/standard        array.c 
>   Log:
>   Fixed some odd behaviours of range() 
>   
>   
> Index: php4/ext/standard/array.c
> diff -u php4/ext/standard/array.c:1.201 php4/ext/standard/array.c:1.202
> --- php4/ext/standard/array.c:1.201   Thu Nov 14 21:16:41 2002
> +++ php4/ext/standard/array.c Sat Nov 23 06:27:56 2002
> @@ -21,7 +21,7 @@
>     +----------------------------------------------------------------------+
>  */
>  
> -/* $Id: array.c,v 1.201 2002/11/15 02:16:41 moriyoshi Exp $ */
> +/* $Id: array.c,v 1.202 2002/11/23 11:27:56 moriyoshi Exp $ */
>  
>  #include "php.h"
>  #include "php_ini.h"
> @@ -1435,19 +1435,29 @@
>  
>       /* If the range is given as strings, generate an array of characters. */
>       if (Z_TYPE_P(zlow) == IS_STRING && Z_TYPE_P(zhigh) == IS_STRING) {
> -             char *low, *high;
> +             unsigned char *low, *high;
>  
>               convert_to_string_ex(&zlow);
>               convert_to_string_ex(&zhigh);
> -             low = Z_STRVAL_P(zlow);
> -             high = Z_STRVAL_P(zhigh);
> +             low = (unsigned char *)Z_STRVAL_P(zlow);
> +             high = (unsigned char *)Z_STRVAL_P(zhigh);
>  
>               if (*low > *high) {             /* Negative steps */
> -                     for (; *low >= *high; (*low) -= step) {
> +                     if (*low - *high < step || step <= 0) {
> +                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "step 
>exceeds the specified range");
> +                             zval_dtor(return_value);
> +                             RETURN_FALSE;
> +                     }
> +                     for (; *low >= *high; (*low) -= (unsigned int)step) {
>                               add_next_index_stringl(return_value, low, 1, 1);
>                       }
>               } else {                                /* Positive steps */
> -                     for (; *low <= *high; (*low) += step) {
> +                     if (*high - *low < step || step <= 0) {
> +                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "step 
>exceeds the specified range");
> +                             zval_dtor(return_value);
> +                             RETURN_FALSE;
> +                     }
> +                     for (; *low <= *high; (*low) += (unsigned int)step) {
>                               add_next_index_stringl(return_value, low, 1, 1);
>                       }
>               }
> @@ -1460,10 +1470,20 @@
>               high = Z_LVAL_P(zhigh);
>  
>               if (low > high) {               /* Negative steps */
> +                     if (low - high < step || step <= 0) {
> +                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "step 
>exceeds the specified range");
> +                             zval_dtor(return_value);
> +                             RETURN_FALSE;
> +                     }
>                       for (; low >= high; low -= step) {
>                               add_next_index_long(return_value, low);
>                       }       
>               } else {                                /* Positive steps */
> +                     if (high - low < step || step <= 0) {
> +                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "step 
>exceeds the specified range");
> +                             zval_dtor(return_value);
> +                             RETURN_FALSE;
> +                     }
>                       for (; low <= high; low += step) {
>                               add_next_index_long(return_value, low);
>                       }       
> 
> 
> 
> -- 
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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

Reply via email to