Skip to content

Panic: "attempt to subtract with overflow" #42

@natevw

Description

@natevw

I am getting frequent panics from the second line of this current_position function when I bring up a project using noline:

noline/noline/src/core.rs

Lines 182 to 185 in 3bfe51d

fn current_position(&self) -> usize {
let pos = self.terminal.current_offset() as usize;
pos - self.prompt.len()
}

attempt to subtract with overflow

This has happened both in std contexts and in no_std but both with the async editor. I haven't fully chased it down but the root explanation seems to be that things go wrong with an unknown (zero) terminal size. Whether it gets into this state because my IO driver isn't quite as well behaved as it'd perhaps like (some of my adapters have returned 0-length "EOF" reads rather than always blocking) or because it's not getting any reply back from the terminal (I'm using a variety of emulators and/or non-emulators on the serial port…) idk.

One initial workaround just to keep plowing ahead is to simply only ever pass "" as the prompt and being zero-length the pos - self.prompt.len() subtraction never goes below zero.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions