Modify

Opened 3 years ago

Last modified 2 years ago

#3943 assigned Bug

Using a function return to increment an counter array element causes TWO function calls

Reported by: RTFC Owned by: Jon
Milestone: Component: AutoIt
Version: 3.3.14.5 Severity: None
Keywords: array index function call Cc:

Description

When a function call yields an index that is used directly to increment an array element, the function is called twice!
Example:

Global $size=5
Global $array[$size]

consolewrite( "standalone call yields: " & _GetRandomIndex($size-1) & @CRLF & @CRLF)
consolewrite( "array index call + increment yields two calls?!" & @CRLF)

$array[_GetRandomIndex($size-1)]+=1

Func _GetRandomIndex($maxindex)
	ConsoleWrite("func called" & @CRLF)
	Return Random(0,$maxindex,1)
EndFunc


Attachments (0)

Change History (7)

comment:1 by anonymous, 3 years ago

Presumably this affects all compound operators, not just +=
The solution would be to not blindly expand A[x]+=y to A[x]=A[x]+y but first capturing x in a temporary.

comment:2 by pixelsearch, 3 years ago

For what it's worth, the related issue appeared for the 1st time with AutoIt version 3.3.10.0

#include <Array.au3>

Local $array[5]
$array[_F()] = "hello"
_ArrayDisplay($array)

Func _F()
        ConsoleWrite("func called" & @CRLF) ; once with 3.3.8.1 , twice with 3.3.10.0
        ; implicit Return 0
EndFunc

2012 - AutoIt 3.3.8.1 => 1 call (tested)
2013 - AutoIt 3.3.10.0 => 2 calls (tested)

comment:3 by J-Paul Mesnage, 3 years ago

Milestone: 3.3.17.0
Owner: set to J-Paul Mesnage
Resolution: Fixed
Status: newclosed

Fixed by revision [12983] in version: 3.3.17.0

comment:4 by J-Paul Mesnage, 3 years ago

Resolution: Fixed
Status: closedreopened

comment:5 by J-Paul Mesnage, 3 years ago

Badly closed

comment:6 by TicketCleanup, 3 years ago

Milestone: 3.3.17.0

Automatic ticket cleanup.

comment:7 by J-Paul Mesnage, 2 years ago

Owner: changed from J-Paul Mesnage to Jon
Status: reopenedassigned

Will be solved as soon Jon Commit the fix to #3003

Modify Ticket

Action
as assigned The owner will remain Jon.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.