Modify

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#3753 closed Bug (Completed)

_GUICtrlListView_SetImageList does not check for errors

Reported by: MrCreatoR Owned by: Melba23
Milestone: 3.3.15.1 Component: AutoIt
Version: 3.3.14.5 Severity: None
Keywords: Cc:

Description

Example:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>

Example()

Func Example()
    Local $hImage, $idListview

    GUICreate("ListView Set Image List", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    GUISetState(@SW_SHOW)
	
    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16))
    _GUICtrlListView_SetImageList($idListview, $hImage, -1)
	
    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

If third parameter ($iType) passed as not supported type (< 0 Or > 2) the script crashes.

GuiListView.au3 (3809) : ==> Variable subscript badly formatted.:
Return Ptr(GUICtrlSendMsg($hWnd, $LVM_SETIMAGELIST, $aType[$iType], $hHandle))
Return Ptr(GUICtrlSendMsg($hWnd, $LVM_SETIMAGELIST, $aType[^ ERROR

I know it's wrong usage, but still should be some error checking in _GUICtrlListView_SetImageList function:

Func _GUICtrlListView_SetImageList($hWnd, $hHandle, $iType = 0)
	$iType = Int($iType) ;In case the $iType passed as other var type than int
	
	If $iType < 0 Or $iType > 2 Then
		Return SetError(1, 0, 0)
		;Or ommit the Return and set:
		$iType = 0
	EndIf
	
	Local $aType[3] = [$LVSIL_NORMAL, $LVSIL_SMALL, $LVSIL_STATE]
	
	If IsHWnd($hWnd) Then
		Return _SendMessage($hWnd, $LVM_SETIMAGELIST, $aType[$iType], $hHandle, 0, "wparam", "handle", "handle")
	Else
		Return Ptr(GUICtrlSendMsg($hWnd, $LVM_SETIMAGELIST, $aType[$iType], $hHandle))
	EndIf
EndFunc

Attachments (0)

Change History (3)

comment:1 by Melba23, 6 years ago

Milestone: 3.3.15.1
Owner: set to Melba23
Resolution: Completed
Status: newclosed

Added by revision [12254] in version: 3.3.15.1

comment:2 by Melba23, 6 years ago

Added by revision [12255] in version: 3.3.15.1

comment:3 by Melba23, 6 years ago

I went with the "set to 0" suggestion.

M23

Modify Ticket

Action
as closed The owner will remain Melba23.

Add Comment


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