[erlang-questions] Why the code will make erlang crash?

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Nov 15 09:18:39 CET 2007


Must be a bug in the regexp module. The regexp code seems to go
into an infinite loop and eats all memory:

$ erl 
Erlang (BEAM) emulator version 5.5.5.5 [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.5.5.5  (abort with ^G)
1> regexp:match("hello", "*lo*").
{error,{illegal,"*"}}
2> regexp:match("hello", "^*lo*").

BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
       (v)ersion (k)ill (D)b-tables (d)istribution


"*lo*" is regarded as an illegal pattern, but
"^*lo*", the same left anchored spins forever.


I think what you ment was:
regexp:match("hello", "^.*lo.*").

The ^* does not make sense; zero or more beginning
of string.



On Thu, Nov 15, 2007 at 03:18:49PM +0800, LUKE wrote:
> -module(libstr).
> -export([exists/2]).
> 
> exists(String,MString)->
>     case regexp:match(String,"(^" ++ MString ++ "*)") of
>         {match,_,_}->true;
>         nomatch->false;
>         {error,Why}->Why
>       end.   
> 
> =============================================
> 4> libstr:exists("hello","hel").
> true
> 
> 5> libstr:exists("hello","lo").
> false
> 
> 6> libstr:exists("hello","lo*").
> false
> 
> 7> libstr:exists("hello","*lo").
> 
> 
> Crash dump was written to: erl_crash.dump
> eheap_alloc: Cannot allocate 1140328500 bytes of memory (of type "heap").
> 
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list