From 0deea46ce7491e5d8168d3f3730868556b1ee221 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Sun, 24 Oct 2010 08:37:27 -0400 Subject: Fix crash in string:copies/2 Using a float for the number of copies results in an infinite loop. Check that the argument is an integer. Reported-By: Eric Pailleau --- lib/stdlib/src/string.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/stdlib/src/string.erl b/lib/stdlib/src/string.erl index 6636a03f06..c987c224db 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) -> -- cgit v1.2.3 From 0af8aefde96691d80fa13a41b878eac0c8f1e9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 29 Oct 2010 11:42:32 +0200 Subject: string_SUITE: Fix copy and paste error in test of string:copies/2 --- lib/stdlib/test/string_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl index 3171b87c44..5df3a869d0 100644 --- a/lib/stdlib/test/string_SUITE.erl +++ b/lib/stdlib/test/string_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2009. All Rights Reserved. +%% Copyright Ericsson AB 2004-2010. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -240,7 +240,7 @@ copies(Config) when is_list(Config) -> ?line "." = string:copies(".", 1), ?line 30 = length(string:copies("123", 10)), %% invalid arg type - ?line {'EXIT',_} = (catch string:chars("hej", -1)), + ?line {'EXIT',_} = (catch string:copies("hej", -1)), ok. words(suite) -> -- cgit v1.2.3 From b9fc6c54079d4932fb156b9dad1f5c3ec946f952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 29 Oct 2010 11:49:46 +0200 Subject: string_SUITE: Add test for string:copies(Str, Float) --- lib/stdlib/test/string_SUITE.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl index 5df3a869d0..452e048dd7 100644 --- a/lib/stdlib/test/string_SUITE.erl +++ b/lib/stdlib/test/string_SUITE.erl @@ -241,6 +241,7 @@ copies(Config) when is_list(Config) -> ?line 30 = length(string:copies("123", 10)), %% invalid arg type ?line {'EXIT',_} = (catch string:copies("hej", -1)), + ?line {'EXIT',_} = (catch string:copies("hej", 2.0)), ok. words(suite) -> -- cgit v1.2.3