The return bug

soulreaping

New Member
Reaction score
17
I've seen in many sites and system that people say "the return bug".

I didn't really understand, what is the bug?

Thanks
 
Reaction score
333
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction


There is a bug that allows you to return data of one type as though it were another. H2I is the most widely used example of the return bug - since a handle variable is actually a reference to an object, when you return it as an integer you get the object's location on the handle stack.
 

Tom Jones

N/A
Reaction score
437
The return bug is simply just that a function will return on the first return it meets. However it's more commonly used to describe this function:
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction
As you see the function is actually not returning a integer, but a handle. Luckily handles are simply integer ids, so this doesn't crash the map due to bad type casting. It also work the other way around:
JASS:
globals
    integer id
endglobals

function I2T takes integer id returns timer
    return id
    return null
endfunction

function ...
    local timer t = I2T(id)

    call TimerStart(t,1,false,null)
endfunction

function ...
    local timer t = CreateTimer()
    set id = H2I(t)
endfunction
This however will crash the map if you use a bad typecast, etc. unit to timer, or at least corrupt the handle stack.

Typecasting from handle to integer and the other way around, has been made obsolete when structs were introduced.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top