Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#3925 closed Bug (Fixed)

With..EndWith should error out when associated with a DllStruct

Reported by: jchd18 Owned by: J-Paul Mesnage
Milestone: 3.3.17.0 Component: Aut2Exe
Version: 3.3.16.1 Severity: None
Keywords: Cc:

Description (last modified by jchd18)

With $X is specified to work only if $X is an object.
Instead it doesn't errour out when $X is a DllStruct.

Uncomment any other datatype below to produce a runtime error.

Local $m[]
Local $b[3]
Local $a = [ _
	DllStructCreate('wchar string[1024]'), _
 _	; 	$m, _
 _	;	$b, _
 _	;	123, _
 _	;	"abc", _
 _	;	Binary(123), _
 _	;	Ptr(123456), _
 _	;	True, _
 _	;	Null _
	ObjCreate("shell.application") _
]
For $v In $a
	ConsoleWrite(VarGetType($v) & @TAB)
	With $v
		ConsoleWrite("passed" & @LF)
	EndWith
Next

Maybe these checks should also be integrated in Au3Check if at all reasonably possible.

Origin thread: https://www.autoitscript.com/forum/topic/209063-beware-of-abusing-undocumented-withendwith-syntax-on-dllstructs/

Attachments (0)

Change History (8)

comment:1 by jchd18, 3 years ago

Description: modified (diff)

comment:2 by jchd18, 3 years ago

Summary: Witn..EndWith should error out when associated with a DllStructWith..EndWith should error out when associated with a DllStruct

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

For me only the doc can be improved as $v.string is a valid expression

Local $m[]
Local $b[3]
Local $a = [ _
    DllStructCreate('wchar string[1024]'), _
 _  ;   $m, _
 _  ;   $b, _
 _  ;   123, _
 _  ;   "abc", _
 _  ;   Binary(123), _
 _  ;   Ptr(123456), _
 _  ;   True, _
 _  ;   Null, _
    ObjCreate("shell.application") _
]
For $v In $a
    ConsoleWrite(VarGetType($v) & @TAB)
    With $v
        ConsoleWrite("passed" & @LF)
		If IsDllStruct($v) Then
			$v.string = "x"
			ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $v.string = ' & $v.string & @CRLF & '>Error code: ' & @error & '    Extended code: ' & @extended & ' (0x' & Hex(@extended) & ')' & @CRLF) ;### Debug Console
		EndIf
	EndWith
Next

comment:4 by anonymous, 3 years ago

doesn't address the memory leak though

in reply to:  4 comment:5 by anonymous, 3 years ago

Replying to anonymous:

doesn't address the memory leak though

Forgot to paste the code from the original thread:

HotKeySet('{esc}',quit)
GUICreate("")
GUISetState()
Local $text
While 1
    $text = state()
    Sleep(10) ; don't remove this, or your RAM will blow up instantly
WEnd

Func state()
     Local Static $struct = DllStructCreate('wchar string[1024]')
     With $struct
          Return .string
     EndWith
EndFunc

Func quit()
     exit
EndFunc

comment:6 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 [12890] in version: 3.3.17.0

comment:7 by anonymous, 3 years ago

Does that fix the memory leak or does it just prevent returning struct members from within a With?

in reply to:  7 comment:8 by J-Paul Mesnage, 3 years ago

Replying to anonymous:

Does that fix the memory leak or does it just prevent returning struct members from within a With?

I can understand that is a new ticket so I leave this one close
Just open a new ticket for the leak memory

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


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