Opened 10 years ago

Closed 10 years ago

#2578 closed Bug (Completed)

_ArrayDelete should return error when element is out of bounds.

Reported by: Jaber Owned by: guinness
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


Currently when an out of bounds index is passed to _ArrayDelete the function clamps it down to within range. This seems wrong. I propose this change:

Func _ArrayDelete(ByRef $avArray, Const $iElement)
	If Not IsArray($avArray) Then Return SetError(1, 0, False)
	Local Const $iUBound = UBound($avArray) - 1
	; Bounds checking
	If $iElement < 0 Then Return SetError(2, 0, False)
	If $iElement > $iUBound Then SetError(3, 0, False)

	; Move items after $iElement up by 1
	Switch UBound($avArray, 0)
		Case 1
			For $i = $iElement To $iUBound - 1
				$avArray[$i] = $avArray[$i + 1]
			ReDim $avArray[$iUBound]
		Case 2
			Local Const $iSubMax = UBound($avArray, 2) - 1
			For $i = $iElement To $iUBound - 1
				For $j = 0 To $iSubMax
					$avArray[$i][$j] = $avArray[$i + 1][$j]
			ReDim $avArray[$iUBound][$iSubMax + 1]
		Case Else
			Return SetError(4, 0, False)

	Return $iUBound
EndFunc   ;==>_ArrayDelete

Attachments (0)

Change History (1)

comment:1 Changed 10 years ago by guinness

  • Milestone set to
  • Owner set to guinness
  • Resolution set to Completed
  • Status changed from new to closed

Added by revision [9385] in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain guinness.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.