Skip to content

Add reader.readLine family of functions to handle CR/LF and line ends on all platforms. #6754

@IridescentRose

Description

@IridescentRose

I found this out while trying to use ZPM to add a package. This is not a ZPM bug as I found, but rather a bug in Zig's std.mem.concat.

Below is a simplified version of the error

const std = @import("std");

pub fn main() !void {
    const name = try std.io.getStdIn().reader().readUntilDelimiterAlloc(std.heap.page_allocator, '\n', 512);
    defer std.heap.page_allocator.free(name);
    std.debug.warn("\n", .{});

    var path = try std.mem.concat(std.heap.page_allocator, u8, &[_][]const u8{
        "packages/",
        name,
        ".json",
    });

    std.debug.warn("{}\n", .{path});
}

Input: myPackage
Output on Ubuntu 20.04: packages/myPackage.zig
Output on Windows: .jsonges/myPackage.zig

This means that the ".json" is overwriting the beginning of the buffer. What's weirder is that when iterating through the entire buffer when copying, every character is printed as the correct string packages/myPackage.zig but the returned result is the other bugged version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions