Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,8 @@ void error(char *msg)
start_idx = offset + 1;

for (offset = 0;
offset < MAX_SOURCE && SOURCE->elements[start_idx + offset] != '\n';
offset < MAX_SOURCE && (start_idx + offset) < SOURCE->size &&
Copy link

@cubic-dev-ai cubic-dev-ai bot Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop initializes offset to SOURCE->size, which causes an out-of-bounds read on the first iteration when accessing SOURCE->elements[offset]. The loop should initialize offset to SOURCE->size - 1 to access the last valid element.

Prompt for AI agents
Address the following comment on src/globals.c at line 1398:

<comment>This loop initializes `offset` to `SOURCE-&gt;size`, which causes an out-of-bounds read on the first iteration when accessing `SOURCE-&gt;elements[offset]`. The loop should initialize `offset` to `SOURCE-&gt;size - 1` to access the last valid element.</comment>

<file context>
@@ -1395,7 +1395,8 @@ void error(char *msg)
 
     for (offset = 0;
-         offset &lt; MAX_SOURCE &amp;&amp; SOURCE-&gt;elements[start_idx + offset] != &#39;\n&#39;;
+         offset &lt; MAX_SOURCE &amp;&amp; (start_idx + offset) &lt; SOURCE-&gt;size &amp;&amp;
+         SOURCE-&gt;elements[start_idx + offset] != &#39;\n&#39;;
          offset++) {
</file context>
Fix with Cubic

SOURCE->elements[start_idx + offset] != '\n';
offset++) {
diagnostic[i++] = SOURCE->elements[start_idx + offset];
}
Expand Down