From ce837f913009f18809f053e6efae06644472e996 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sun, 5 Nov 2023 19:57:19 +0100 Subject: [PATCH] fix: prevent segfault in case ispell does not provide any output --- README.md | 2 +- src/main.zig | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf04f3f..a6f57f5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ zig build -Doptimize=ReleaseFast If you wish to install it into */usr/local/* you will have to provide the prefix argument: ```sh -sudo zig build install -p /usr/local/ -DoptimizeReleaseFast +sudo zig build install -p /usr/local/ -Doptimize=ReleaseFast ``` This was build using zig 0.12.0.dev but should work with the most recent version of zig. diff --git a/src/main.zig b/src/main.zig index 35d580e..f203a8c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -85,6 +85,12 @@ pub fn main() !void { } std.mem.copy(u8, content, output[start_idx .. output.len - 1]); defer allocator.free(content); + // prevent access to result if the ispell output has only a single line + if (output.len - start_idx > 0) { + try stdout_writer.print("{s}", .{word}); + try bw.flush(); // don't forget to flush! + return; + } if (content[0] == '*' or content[0] == '+') { // given word was correct so just return the input as no replacement is necessary