Re: Multiple selection causing application crash

Jean Lalonde <[email protected]> Thu, 16 Jan 2025 14:53:45 -0800 (PST)
Newsgroups gmane.comp.lib.scintilla.devel
Message-ID <[email protected]>
>  A too-small buffer will overflow and potentially cause trouble. The size 
required should be calculated first by calling SCI_GETSELTEXT with a NULL 
argument, then a new buffer allocated of the correct size which is then 
used for getting the actual value. There may be a +1 that is needed for the 
NUL byte terminator - this was changed at some point but allocating too 
much is safer.

Just a follow up. This code now works:

; this code snippet is AutoHotkey v1.1
intLen := o_Sci.GETSELTEXT(0, "") ; "" is interpreted as NULL in AHK
VarSetCapacity(strText, intLen + 1, 0)
o_Sci.GETSELTEXT(0, &strText) ; o_Sci is an instance of the Scintilla class 
wrapper (Scintilla.ahk)
strText := StrGet(&strText, "UTF-8")
MsgBox, intLen: %intLen% / strText: %strText%

Thanks for your help,
Jean

PS: Anybody using AutoHotkey (v1 or v2) interested in working on a 
Scintilla class wrapper supporting the most recent Scintilla+Lexilla? You 
can contact me at [email protected].

Le mardi 14 janvier 2025 à 21 h 46 min 32 s UTC-5, Neil Hodgson a écrit :

> Jean:
>
> It was a call to the command SCI_GETSELTEXT() that I did not suspect to 
> occur in a piece of code executed every 500 ms to update a value in the 
> app's status bar.
> I could not tell why this command crashed when called with multiple 
> selection. Could it be related to the buffer size? I can post code if you 
> wish.
>
>
>    A too-small buffer will overflow and potentially cause trouble. The 
> size required should be calculated first by calling SCI_GETSELTEXT with a 
> NULL argument, then a new buffer allocated of the correct size which is 
> then used for getting the actual value. There may be a +1 that is needed 
> for the NUL byte terminator - this was changed at some point but allocating 
> too much is safer.
>
>    Neil
>

-- 
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/67523c13-4046-4942-9321-094dba6f917fn%40googlegroups.com.