Skip to content

dd on line 1 crashes the program. #1

@JuhaJGamer

Description

@JuhaJGamer

Yeah, an issue for a Minecraft version of vi.

Anyway,

Steps to reproduce

  1. Open vi on any CC: Tweaked computer.
  2. Enter insert mode, write something on the first line and return to normal mode
  3. Write dd

Expected behaviour

The first line should be blanked, returning you to an empty file

Actual behaviour

vi.lua:573: attempt to get length of field '?' (a nil value)
|Line 573
|        if newX > #lines[newY] then
|
> _

I do see that it is marked with TODO: Fix, and I think the time may be approaching when the number of users (approximately 1) has risen so high that the application may require maintenance again.

Non-expert diagnosis

You're deleting the line. That's fine, unless we're on the first line, in which case setCursor tries to read the length of that line. lines should be used safely if it can ever be empty, or unsafely only if it is guaranteed to never be. I've personally taken the liberty of defining

local function removeLine(lineY)
    table.remove(lines,lineY)
    if #lines == 0 then
        table.insert(lines, "")
    end
end

and replaced each table.remove(lines,y) with it. This seems to have largely repaired the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions