PR# 14796 MEMORY:find_all_instances can get a stack overflow

Problem Report Summary
Submitter: randyjohn
Category: Runtime
Priority: Medium
Date: 2008/09/17
Class: Bug
Severity: Non-critical
Number: 14796
Release: 6.3.7.4554
Confidential: No
Status: Open
Responsible: manus_eiffel
Environment: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; WOW64; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; .NET CLR 3.0.04506.648)
Synopsis: MEMORY:find_all_instances can get a stack overflow

Description
Because MEMORY:find_all_instances is recursive, it isn't too difficult to cause a stack overflow.  Currently, I have set my stack to 100 MB (and I just had a crash).  In addition to dying, the debugger does not always catch the error and the program mysteriously exits.  I don't know how to reproduce that part.  In the example below (-STACK:5000000) I use a LIST but the actual structure that I'm having a problem with is somewhat tree-like and can be traversed recursively without exceeding a depth of 20-30.  Unfortunately, 'find_all_instances' has no way of knowing what the optimal traversal strategy is and performs an almost linear search (like below).

The solution is to make 'find_all_instances' non-recusive.
   Randy

class ROOT

inherit
	MEMORY

create
	make

feature

	make is
	local
		i: INTEGER
		l_linked_list: TWO_WAY_LIST[INTEGER]
	do
		create l_linked_list.make

		from
			i := 0
		until
			i>100000
		loop
			l_linked_list.extend(i)
			i := i + 1
		end

		memory_map.do_nothing		-- Succeeds.

		from
			i := 0
		until
			i>500000
		loop
			l_linked_list.extend(i)
			i := i + 1
		end

		memory_map.do_nothing		-- Fails.
	end
end
To Reproduce

										
Problem Report Interactions
From:larryl    Date:2009/08/06    Download   
This bug is till reproducible in Eiffel Studio 6.5 (6.5.7.9743 GPL Edition - linux-x86)

When reproducing, I get a precondition violation in {ARRAYED_LIST}.put_i_th when executing line "memory_map.do_nothing      -- Succeeds." After comment that line and restart, there is:

Segmentation fault: Operating system signal. 

when executing line "memory_map.do_nothing      -- Fails.".

Reproduce demo project attached.

Attachment: bug14796.7z     Size:1002