diff options
author | Colin Viebrock <cmv@php.net> | 2000-09-05 18:25:58 +0000 |
---|---|---|
committer | Colin Viebrock <cmv@php.net> | 2000-09-05 18:25:58 +0000 |
commit | 6f59f8b0785f07d5450bbceb0cf67455eb65c1d8 (patch) | |
tree | 390b47be657f0ac9394b29a7d53ec175bdbdb5d3 /ext | |
parent | 81ddcd0b2b523228c9409e29a2559ad61f0ce697 (diff) | |
download | php-git-6f59f8b0785f07d5450bbceb0cf67455eb65c1d8.tar.gz |
str_repeat() should be able to handle multipliers of 0 gracefully, IMHO ...
Hope no one disagrees. :)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/string.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index 9df17e46e0..d95c96b900 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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); |