editorDelRow increments row indices instead of decrementing them

Open
#117 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
cli

Research direction

Start at editorDelRow around line 628 and compare its row-shifting loop with editorInsertRow around line 597; inspect editorUpdateSyntax around line 408 to understand the affected idx lookup. Done when deleting a row leaves subsequent row indices aligned with their positions and the reported multi-line-comment crash path no longer receives corrupted indices.

Written by the indexing model from the issue text.

Description

In editorDelRow (line 628), after memmove shifts rows left to fill the gap, the loop updates row indices:

for (int j = at; j < E.numrows-1; j++) E.row[j].idx++;

This increments idx, but deletion should decrement it. After deleting row 5, row 6 (now at position 5) should have idx = 5, not idx = 7.

Compare with editorInsertRow (line 597), which correctly increments after shifting rows right:

for (int j = at+1; j <= E.numrows; j++) E.row[j].idx++;

The fix is E.row[j].idx-- instead of E.row[j].idx++.

The corrupted idx values cause editorUpdateSyntax to access wrong rows when checking for open multi-line comments (line 408), which can lead to the segfault reported in #28. PR #20 contains a fix but was never merged.

Dominant language
C
Stars
9.1k
Forks
1k
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from antirez/kilo

All issues in antirez/kilo

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.