gscintilla giving error "[ERROR] Overflow in a dynamically allocated memory block.

Just starting out? Need help? Post your questions and find answers here.
TRS-Eric
User
User
Posts: 16
Joined: Thu Apr 23, 2020 7:42 pm

gscintilla giving error "[ERROR] Overflow in a dynamically allocated memory block.

Post by TRS-Eric »

The error is occurring around line 309:

Code: Select all

caretPos = ScintillaSendMessage(*this\id, #SCI_GETCURLINE, numUtf8Bytes+1, *utf8Buffer)
I removed the +1 on numUtf8Bytes and that fixed it, but I'm not entirely sure what this does, so I'm worried about problems later.

Any ideas on how to fix? The error occurs when editing UTF8 data, possibly corrupt? The data loaded is UTF8-bom according to Notepad++

See screenshot: https://imgur.com/a/bHj1aOL

Image
---
BASIC related discord: https://discord.gg/KS4en5y5j4
PeDe
Enthusiast
Enthusiast
Posts: 278
Joined: Sun Nov 26, 2017 3:13 pm

Re: gscintilla giving error "[ERROR] Overflow in a dynamically allocated memory block.

Post by PeDe »

Scintilla can return zero at line 301. For example, if the cursor is in the last line without text. Line 309 then passes a pointer to an empty memory location. This should trigger the error. So you should check the return of line 301 for zero, and not assume that there is always a length greater than zero.

Edit: Line 302 also checks wrong, minus one also gives True, only zero gives False.

Edit2: Your error probably has another cause. You can't allocate memory with zero bytes, PB will give an error. So the return of line 301 will not be 0 or -1.

But this is only assumed, I only read your code.

Peter
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: gscintilla giving error "[ERROR] Overflow in a dynamically allocated memory block.

Post by spikey »

Try changing line 302 to read:

Code: Select all

If numUtf8Bytes > 0
If Peter is right that should fix it.
TassyJim
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: gscintilla giving error "[ERROR] Overflow in a dynamically allocated memory block.

Post by TassyJim »

I had the same problem when I changed to PB603
I made the same change and in a few other places as well

Code: Select all

numUtf8Bytes = ScintillaSendMessage(*this\id, #SCI_GETCURLINE, 0, 0) ;- 1 ;Includes the null, hence the -1. removed to suit pb603
  If numUtf8Bytes 
    bufferPtr = AllocateMemory(numUtf8Bytes+2) ; added an extra byte to suit pb603
    If bufferPtr
      If *this\state & #GOSCI_LEXERSTATE_ENABLECALLTIPS
        blnProceedWithCallTip = #True
      EndIf
      *utf8Buffer = bufferPtr
      caretPos = ScintillaSendMessage(*this\id, #SCI_GETCURLINE, numUtf8Bytes, *utf8Buffer) ; +1 removed to suit pb603
I think something changed in the latest scintilla update.
My reasoning is, if in doubt, include a few a extra bytes 'just in case'

I ended up searching my full project and added extra bytes to all likely AllocateMemory functions.
It seems to have worked.

Jim
Post Reply