Modify

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: 3.3.11.0 Component: AutoIt
Version: 3.3.10.1 Severity: None
Keywords: Cc:

Description

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]
			Next
      
			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]
				Next
			Next
      
			ReDim $avArray[$iUBound][$iSubMax + 1]
      
		Case Else
			Return SetError(4, 0, False)
	EndSwitch

	Return $iUBound
EndFunc   ;==>_ArrayDelete

Attachments (0)

Change History (1)

comment:1 Changed 10 years ago by guinness

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

Added by revision [9385] in version: 3.3.11.0

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

Action
as closed The owner will remain guinness.
Author


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

 
Note: See TracTickets for help on using tickets.