A crash in file editing when appending at the end of a file was fixed by normalizing -1 to n (insert at end) instead of n+1. The patch restricts -1 to append mode and rejects it for replace/delete operations to prevent silent overwriting of the last line, and ensures insert offset is computed as an integer to avoid heap-buffer-overflow.