]> granicus.if.org Git - php/commitdiff
str_repeat() should be able to handle multipliers of 0 gracefully, IMHO ...
authorColin Viebrock <cmv@php.net>
Tue, 5 Sep 2000 18:25:58 +0000 (18:25 +0000)
committerColin Viebrock <cmv@php.net>
Tue, 5 Sep 2000 18:25:58 +0000 (18:25 +0000)
Hope no one disagrees. :)

ext/standard/string.c

index 9df17e46e004306fa1cd8716e5b8c03eea140997..d95c96b900591a2f16375e136a037d820e8dedb5 100644 (file)
@@ -2553,8 +2553,8 @@ PHP_FUNCTION(str_repeat)
        convert_to_string_ex(input_str);
        convert_to_long_ex(mult);
        
-       if ((*mult)->value.lval < 1) {
-               php_error(E_WARNING, "Second argument to %s() has to be greater than 0",
+       if ((*mult)->value.lval < 0) {
+               php_error(E_WARNING, "Second argument to %s() has to be greater than or equal to 0",
                                  get_active_function_name());
                return;
        }
@@ -2563,6 +2563,10 @@ PHP_FUNCTION(str_repeat)
        if ((*input_str)->value.str.len == 0)
                RETURN_STRINGL(empty_string, 0, 1);
        
+       /* ... or if the multiplier is zero */
+       if ((*mult)->value.lval == 0)
+               RETURN_STRINGL(empty_string, 0, 1);
+       
        /* Initialize the result string */      
        result_len = (*input_str)->value.str.len * (*mult)->value.lval;
        result = (char *)emalloc(result_len + 1);