Incidencia #39922

script crashes with stack overflow when jumping out of a while loop several times

Abrir Fecha: 2020-01-16 15:17 Última actualización: 2023-01-10 08:33

Informador:
(Anónimo)
Propietario:
(Ninguno)
Tipo:
Estado:
Open
Componente:
Hito:
(Ninguno)
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Ninguno
Fichero:
Ninguno
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Details

num = 0

:MAIN

num = num+1

int2str STRN num

title = 'number of loops before stack overflow: '

strconcat title STRN

settitle title

maxtime = 2

while maxtime>1

testlink
if result=2 goto TEST_END
messagebox 'port not available!' 'State'
pause 1
maxtime = maxtime-1

endwhile

:TEST_END

pause 1

goto MAIN

Ticket History (3/4 Histories)

2020-01-16 15:17 Updated by: None
  • New Ticket "script crashes with stack overflow when jumping out of a while loop several times" created
2022-11-24 04:21 Updated by: None
Comentario

Having the same issue. Runs the whole script top to bottom 8 times, but the ninth run will have stack overflow error the first time it enters a while loop. The repeat of the script is a goto like in the example above. Is there a better way to loop back to the beginning of a script? Or some way to avoid this issue?

2022-11-24 06:31 Updated by: gregj2022
Comentario

This may have been fixed if it was ever an issue. I resolved my issue by using 'call/return' instead of 'goto'. I have a 400+ line TTL file that consistently caused a 'Stack overflow' error on the 9th loop back to the top of the file. After refactoring it to use 'call' and 'return' I am on the 12th run without issue. I'll come back and update this if it crashes on the 1000th run or something.

Your 'goto MAIN' commands may have been the issue. Each 'goto MAIN' may not close/release the previous instance of 'MAIN', so the stack may pile up with each goto you add. Like MAIN nested into MAIN into MAIN in a chain until the stack overflow happens. Try something like what I edited below. I see this is years old, but leaving this here in case anybody else like me runs into this issue and can't google up a solution.

It splits up the script into functions that can be called with 'call <label>' and returns to the line they were called from with 'return'. No need to 'goto' anywhere. 'goto' commands can be used for error handling and debugging but aren't good for looping because of this.

;#### MAIN ####

num = 0

until num=1000

int2str STRN num

title = 'number of loops before stack overflow: '

strconcat title STRN

settitle title

call checkthelink

call addtocounter

enduntil

exit

;#### Functions ####

:addtocounter

num = num+1

return

:checkthelink

maxtime = 2

while maxtime>1

testlink

if result=2 then

return

endif

statusbox 'port not available!' 'State'

pause 1

closesbox

maxtime = maxtime-1

endwhile

return

For the algorithms: Tera Term Macro Loop Goto Call Return Stack Overflow While Until

2023-01-10 08:33 Updated by: nmaya
  • Prioridad Update from 7 to 5 - Medium

Attachment File List

No attachments

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Entrar