Fix bad memory access in ReplaceAll

This commit is contained in:
Krzosa Karol
2026-03-05 16:55:58 +01:00
parent 52c55e27d9
commit 9b2c8626d4
4 changed files with 7 additions and 2 deletions

View File

@@ -1152,6 +1152,7 @@ API void InitBuffer(Allocator allocator, Buffer *buffer, BufferID id = {}, Strin
if (!buffer->no_line_starts) { if (!buffer->no_line_starts) {
Add(&buffer->line_starts, (Int)0); Add(&buffer->line_starts, (Int)0);
} }
if (DebugTraceBufferInits) printf("InitBuffer %.*s %p\n", (int)name.len, name.data, buffer->data);
} }
API void DeinitBuffer(Buffer *buffer) { API void DeinitBuffer(Buffer *buffer) {
@@ -1161,6 +1162,7 @@ API void DeinitBuffer(Buffer *buffer) {
Dealloc(&buffer->line_starts); Dealloc(&buffer->line_starts);
DeallocHistoryArray(&buffer->undo_stack); DeallocHistoryArray(&buffer->undo_stack);
DeallocHistoryArray(&buffer->redo_stack); DeallocHistoryArray(&buffer->redo_stack);
if (DebugTraceBufferInits) printf("DeinitBuffer %.*s %p\n", (int)buffer->name.len, buffer->name.data, buffer->data);
} }
// Indexing starts from 0 not 1 because this routine creates also the zero buffer // Indexing starts from 0 not 1 because this routine creates also the zero buffer

View File

@@ -9,6 +9,7 @@ bool SearchCaseSensitive = false;
bool SearchWordBoundary = false; bool SearchWordBoundary = false;
bool BreakOnError = false; bool BreakOnError = false;
Int ErrorCount; Int ErrorCount;
bool DebugTraceBufferInits = false;
Allocator SysAllocator = {SystemAllocatorProc}; Allocator SysAllocator = {SystemAllocatorProc};
float DPIScale = 1.0f; float DPIScale = 1.0f;

View File

@@ -140,7 +140,7 @@ void CO_ReplaceAll(mco_coro *co) {
field_seek = BaseFindNext(main.buffer, u"for::", MakeCaret(0), SeekFlag_None); field_seek = BaseFindNext(main.buffer, u"for::", MakeCaret(0), SeekFlag_None);
Range range = {field_seek.range.max, main.buffer->len}; Range range = {field_seek.range.max, main.buffer->len};
needle = GetString(main.buffer, range); needle = Copy16(ctx->arena, GetString(main.buffer, range));
} }
{ {

View File

@@ -1,4 +1,6 @@
/* /*
- [x] ReplaceAll - heap-use-after-free address, how to debug? I think would be nice to iterate all buffer ids and their addresses along with the state
- [x] BRO, the caret teleports on linux when I press the arrow for too long - [x] BRO, the caret teleports on linux when I press the arrow for too long
- [ ] Report SDL newest vs SDL previous version on wayland - [ ] Report SDL newest vs SDL previous version on wayland
@@ -900,8 +902,8 @@ int main(int argc, char **argv, char **envp)
char **argv = __argv; char **argv = __argv;
AttachConsole(ATTACH_PARENT_PROCESS); AttachConsole(ATTACH_PARENT_PROCESS);
#endif #endif
InitScratch();
InitOS(ReportErrorf); InitOS(ReportErrorf);
InitScratch();
ProjectFolder = GetWorkingDir(Perm); ProjectFolder = GetWorkingDir(Perm);
HomeFolder = SDL_GetUserFolder(SDL_FOLDER_HOME); HomeFolder = SDL_GetUserFolder(SDL_FOLDER_HOME);