Jump to content

Question about Functions and Buffer Overflow


Guest WorldWatcher
 Share

Recommended Posts

Guest WorldWatcher

Hi, I am pretty new to AutoIt and I was wondering about some code i saw recently.

A friend of mine often uses code like this:

Func example()

;do some stuff

If $var = 1 Then

example()

Else

;do some other function that eventually never returns

EndIf

;do some more stuff

EndFunc

The clue here is that the If-part of this example()-method won't finish, ever.

His scripts often crash ("AutoIt3.exe has generated errors").

I think this is because of this bad programming practice(maybe buffer overflow cause AutoIt3 keeps all return addresses to former methods on its stack), but he thinks it is because of AutoIt3 itself("It is only a beta").

Can someone shed some light here? :whistle:

Link to comment
Share on other sites

Example of bad programming.

chewgum()

function chewgum()
If $var = 1 Then
run(put  stick of gum in mouth)
chewgum()
sleep(1000)
endfunc

You wouldn't keep sticking pieces of gum intoyour mouth one after anouther. Eventually your mouth will fill unless you spit one out, or chew it, or swallow it, etc.

If he wanted an endless loop, until $var =1 it would be simple to just

Func example()
While $var <> 1
;do some stuff
WEnd
;do some other function
While $var = 1
;do some more stuff
WEnd
EndFunc

It looks like the intention might have been to do something that might change the value of $var to equal 1, and once that happened to do something else. This would be better done with While perhapse. Calling a function from a funtion is nice, but don't get into a situation where it can end up calling itself.

AutoIt has a lot of tools, usually bad loops like this come from using the wrong tool for the job, because you are more familiar with that. Anyone use a knife instead of a screwdriver?

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...