[PATCH] Fix crash in string:copies/2

Michael Santos <>
Sun Oct 24 14:37:27 CEST 2010


Using a float for the number of copies results in an infinite loop.
Check the argument is an integer.

Reported-By: Eric Pailleau
---
 lib/stdlib/src/string.erl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/stdlib/src/string.erl b/lib/stdlib/src/string.erl
index 6636a03..c987c22 100644
--- a/lib/stdlib/src/string.erl
+++ b/lib/stdlib/src/string.erl
@@ -201,7 +201,7 @@ chars(C, 0, Tail) when is_integer(C) ->
 
 -spec copies(string(), non_neg_integer()) -> string().
 
-copies(CharList, Num) when is_list(CharList), Num >= 0 ->
+copies(CharList, Num) when is_list(CharList), is_integer(Num), Num >= 0 ->
     copies(CharList, Num, []).
 
 copies(_CharList, 0, R) ->
-- 
1.7.0.4



More information about the erlang-patches mailing list