Opened 14 years ago

Closed 14 years ago

#6435 closed bug (fixed)

Issues in TextGapBuffer

Reported by: BNickName Owned by: zooey
Priority: normal Milestone: R1
Component: Kits/Interface Kit Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

There are a few issues with the TextGapBuffer. Stefano or me will probably fix it soon. but since one of them involves reading past buffers someone might want to fix this earlier.

(For an understanding of the text gap buffer see http://www.codeproject.com/KB/recipes/GenericGapBuffer.aspx#GapBufferWorks or "The Craft of Text Editing" http://www.finseth.com/craft/)

The first problem is that RemoveRange resizes the gap each time after removing content, to make sure the gap doesn't grow too big:

if (fGapCount > kTextGapBufferBlockSize)

SizeGapTo(kTextGapBufferBlockSize);

In practice however, this means that every time a character is deleted, the buffer is being resized.

The bigger problem however is that SizeGapTo resizes the buffer (realloc) before moving the gap (memmove). This means that you lose the content of the buffer in case the gap is not at the end (the gap position depends on where the user is editing). As well as read beyond the reallocated space.

So each time the user deletes a character, there is a possibility that he loses text at the end of the buffer, in case the realloc would move the memory.

Change History (3)

comment:1 by axeld, 14 years ago

Owner: changed from axeld to zooey
Status: newassigned

Maybe zooey would like to have a go at that one - IIRC he liked working on BTextView a lot :-)

in reply to:  1 comment:2 by zooey, 14 years ago

Status: assignedin-progress

Replying to axeld:

Maybe zooey would like to have a go at that one - IIRC he liked working on BTextView a lot :-)

You wait, my friend, you wait ... muhaha!

comment:3 by zooey, 14 years ago

Resolution: fixed
Status: in-progressclosed

Should be fixed in hrev37987 and hrev37989 - thanks!

Note: See TracTickets for help on using tickets.