#2085 closed Bug (No Bug)
DllStructGetData crash with char array
| Reported by: | anonymous | Owned by: | |
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.8.0 | Severity: | None |
| Keywords: | Cc: |
Description
DllStructGetData seems to verify or fetch whole data of structs created from string pointers. Comment out the first region to see a work-around.
Local $sA = "String A", $xA = StringToBinary($sA) & "00"
Local $sB = "String B", $xB = StringToBinary($sB) & "00"
; A binary string that contains the null delimited strings
Local $xAB = $xA & StringTrimLeft($xB, 2)
; Verify data
ConsoleWrite($xA & @LF & $xB & @LF & $xAB & @LF & @LF)
Local $tBuffer = DllStructCreate("byte[" & BinaryLen($xAB) & "]")
Local $pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, 1, $xAB)
; Verify data
ConsoleWrite(DllStructGetData($tBuffer, 1) & @LF)
#region >_<
; Create a dllstruct used for getting strings of max size
Local $tPath = DllStructCreate("char[1048576]", $pBuffer)
ConsoleWrite(DllStructGetData($tPath, 1) & @LF) ; crash
#endregion
#region Q(0_0 Q)
Local $iSize = _StrLen($pBuffer)
ConsoleWrite($iSize & @LF)
Local $tPath = DllStructCreate("char[" & $iSize & "]", $pBuffer)
ConsoleWrite(DllStructGetData($tPath, 1) & @LF)
#endregion
Func _StrLen(Const $pString)
Local $aResult = DllCall("msvcrt.dll", "int:cdecl", "strlen", "ptr", $pString)
Return $aResult[0]
EndFunc
P.S.
I don't need an array that is that big. It happens even with smaller arrays.
P.S. 2
If, for some reason, it doesn't crash even with 1 MB, try a bigger one.
Attachments (0)
Change History (2)
follow-up: 2 comment:1 by , 14 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
comment:2 by , 14 years ago
Replying to trancexx:
When structure is created at address specified by the user (your $pBuffer) AutoIt doesn't do any memory allocation. It assumes the user is smart enough to check, or to know in advance how big the pointed memory space is. It's you who decided to create bad structure in first place.
This is not a bug. It's just careless bad programmer you.
Bad programmer.... :)

When structure is created at address specified by the user (your $pBuffer) AutoIt doesn't do any memory allocation. It assumes the user is smart enough to check, or to know in advance how big the pointed memory space is. It's you who decided to create bad structure in first place.
This is not a bug. It's just careless bad programmer you.