[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Smashing the stack
From: |
Daniel J Sebald |
Subject: |
Re: Smashing the stack |
Date: |
Fri, 25 May 2012 23:29:39 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16 |
On 05/25/2012 09:41 PM, Dmitri A. Sergatskov wrote:
On Fri, May 25, 2012 at 6:38 PM, Doug Stewart<address@hidden> wrote:
On Fri, May 25, 2012 at 4:40 PM, Jordi GutiƩrrez Hermoso
<address@hidden> wrote:
This seems like a rather esoteric thing to do, but:
a = {}
for i = 1:1e6
a = {rand, a};
endfor
for i = 2:1e6
a = a{2};
endfor
This segfaults for me after a relatively long time, presumably since
the call stack goes up to about 1e6 stack frames.
Is it worthwhile trying to fix this?
- Jordi G. H.
Works OK for me in the GUI with todays compile.
octave:1> run '/home/doug/test55.m'
a = {}(0x0)
octave:2> whos a
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
a 1x2 8 cell
Total is 2 elements using 8 bytes
octave:3>
Doug, something doesn't seem right there, being only 8 bytes. I run the
script with something that doesn't cause a segmentation fault and see a
much greater number of bytes:
octave:1> a = {}
a = {}(0x0)
octave:2> for i = 1:1e5
a = {rand, a};
endfor
octave:3> whos a
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
a 1x2 800000 cell
Total is 2 elements using 800000 bytes
--
DAS
https://linuxcounter.net/user/206392.html
But try with the only first loop:
a = {}
for i = 1:1e6
a = {rand, a};
endfor
whos a
Dmitri.
--
I tried some lower values than 1e6, and see similar sorts of behavior:
octave:1> a = {}
a = {}(0x0)
octave:2> for i = 1:1.5e5
a = {rand, a};
endfor
octave:3> exit
Segmentation fault (core dumped)
If anything, a more graceful failure would be nice. If it is stack
overflow, that's not always the easiest to fix with non-firmware
solutions (e.g., a processor which has its own stack protecting
register) because even if the stack is checked from time to time it can
still overflow and come back within range. Would probably need some
padding to prevent that.
Dan