Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.io.Reader.readUntilDelimiter* functions lose last byte if it is past the max size #9594

Closed
Vexu opened this issue Aug 20, 2021 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Aug 20, 2021

Seems like this could be resolved by requiring space for the delimiter.

More tests are also needed.

@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. labels Aug 20, 2021
@Vexu Vexu added this to the 0.9.0 milestone Aug 20, 2021
@jmc-88
Copy link
Sponsor Contributor

jmc-88 commented Oct 28, 2021

Could you elaborate on "this could be resolved by requiring space for the delimiter"? I'm not sure I understand the proposal.

const std = @import("std");

test "9594" {
    const reader = std.io.fixedBufferStream("1234567\n").reader();

    var buf: [3 + 1]u8 = undefined; // I want to read at most 3 byte, + 1 for the delimiter
    try std.testing.expectError(error.StreamTooLong, reader.readUntilDelimiter(&buf, '\n')); // ← still eats the '5'?
    try std.testing.expectEqualStrings("567", try reader.readUntilDelimiter(&buf, '\n')); // ← reads "67\n" instead
}

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 24, 2021
scorphus added a commit to scorphus/zig that referenced this issue Jan 9, 2022
scorphus added a commit to scorphus/zig that referenced this issue Jan 10, 2022
scorphus added a commit to scorphus/zig that referenced this issue Jan 15, 2022
scorphus added a commit to scorphus/zig that referenced this issue Jan 15, 2022
Vexu pushed a commit that referenced this issue Jan 24, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.9.1 Jan 25, 2022
@andrewrk andrewrk closed this as completed Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants