← Commit list

05e5d6a38

Petja Patjas
Petja Patjas
2024-07-11
SUCCESS Duration: 156s

Subject

vi: Ensure that the edit buffer ends in a newline

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

editors/vi.c+4 -3
@@ -2315,9 +2315,10 @@ static int init_text_buffer(char *fn)
update_filename(fn);
rc = file_insert(fn, text, 1);
- if (rc < 0) {
- // file doesnt exist. Start empty buf with dummy line
- char_insert(text, '\n', NO_UNDO);
+ if (rc <= 0 || *(end - 1) != '\n') {
+ // file doesn't exist or doesn't end in a newline.
+ // insert a newline to the end
+ char_insert(end, '\n', NO_UNDO);
}
flush_undo_data();