mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-12 17:08:39 -09:00
Fix infinite loop when reading config file on Zig 0.15.2
Works around Zig issue https://github.com/ziglang/zig/issues/25664 Fixes #266
This commit is contained in:
parent
14bb8d0dd1
commit
f452244576
1 changed files with 11 additions and 2 deletions
13
src/util.zig
13
src/util.zig
|
|
@ -231,9 +231,18 @@ pub const LineReader = if (@hasDecl(std.io, "bufferedReader")) struct {
|
|||
}
|
||||
|
||||
pub fn read(s: *@This()) !?[]u8 {
|
||||
return s.rd.interface.takeDelimiterExclusive('\n') catch |err| switch (err) {
|
||||
error.EndOfStream => null,
|
||||
// Avoid takeDelimiterExclusive() for now, it's bugged in 0.15.2: https://github.com/ziglang/zig/issues/25664
|
||||
const r = &s.rd.interface;
|
||||
const result = r.peekDelimiterInclusive('\n') catch |err| switch (err) {
|
||||
error.EndOfStream => {
|
||||
const remaining = r.buffer[r.seek..r.end];
|
||||
if (remaining.len == 0) return null;
|
||||
r.toss(remaining.len);
|
||||
return remaining;
|
||||
},
|
||||
else => |e| return e,
|
||||
};
|
||||
r.toss(result.len);
|
||||
return result[0 .. result.len - 1];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue