Skip to content

Commit

Permalink
Demo: fix line_buffer issue in ParseDemoMarkerTags
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 2, 2023
1 parent 10bcc8f commit 472809d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8360,9 +8360,11 @@ namespace ImGuiDemoMarkerCodeViewer_Impl
ImVector<DemoMarkerTag> r;
{
char line_buffer[2048];
memset(line_buffer, 0, 2048);
char tag_buffer[IMGUI_DEMO_MARKER_MAX_TAG_LENGTH];
for (int line_number = 0; line_number < lines.size(); ++line_number)
{
const auto& line = lines[line_number];
ImCStringUtils::CopyTextRange(lines[line_number].b, lines[line_number].e, line_buffer, 2048);
if (ImCStringUtils::CodeLineStartsWith(line_buffer, "IMGUI_DEMO_MARKER("))
{
Expand Down Expand Up @@ -8396,9 +8398,9 @@ namespace ImGuiDemoMarkerCodeViewer_Impl
~DemoCodeWindow()
{
if (SourceCode)
IM_DELETE(SourceCode);
IM_FREE(SourceCode);
if (SourceLineNumbersStr)
IM_DELETE(SourceLineNumbersStr);
IM_FREE(SourceLineNumbersStr);
}

void NavigateTo(int line_number)
Expand Down Expand Up @@ -8524,9 +8526,11 @@ namespace ImGuiDemoMarkerCodeViewer_Impl
}
fseek(f, 0, SEEK_END);
size_t file_size = (size_t) ftell(f);
SourceCode = (char *) IM_ALLOC(file_size * sizeof(char));
SourceCode = (char *) IM_ALLOC((file_size + 1)* sizeof(char));
rewind(f);
fread(SourceCode, sizeof(char), file_size, f);
size_t nread = fread(SourceCode, sizeof(char), file_size, f);
IM_ASSERT(nread == file_size);
SourceCode[file_size] = '\0';
fclose(f);
}

Expand Down

0 comments on commit 472809d

Please sign in to comment.