Bug in string.erl

Robert Virding robert.virding@REDACTED
Wed Nov 5 23:10:13 CET 2003


----- Original Message ----- 
From: "Joe Armstrong" <joe@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Tuesday, November 04, 2003 8:02 PM
Subject: Bug in string.erl

>  But is was an atom ... did I get an exit - No for
> 
>  > string:substr(aa, 1, 20). 
>  []
> 
>  Wow (Static type systems 1, Joe 0)
> 
>  The code in string.erl says 
> 
>  --- quote ---
> 
>  substr1([C|String], L) when L > 0 -> [C|substr1(String, L-1)];
>  substr1(String, L) -> []. %Be nice!
> 
>  --- end quote ---
> 
>  I rather like the "%Be nice!" comment.
> 
>  IMHO all the functions in string should exit when the "string" argument
> is not a list - I'm not asking that you "deep check" the list but a little
> help might be nice

Yes it is defintely a bug. The problem is that I was trying to be nice in the case where the desried substring length is longer than the remaining string inwhich case the substring  just gets the remaining characters. So

string:substr("abcd", 2, 5) -> "cd"

The second should of course be:

substr1(String, L) when list(String) -> []. %Be nice!

Robert
 



More information about the erlang-questions mailing list