Description
I have a simple program to take input from the user, then print what the user typed right back out. Along with the length of the user's input.
I am using CLion.
My build.zig file is the standard auto-generated one.
My build configuration is normal except I added the "run" step to it in order to run my code.
const std = @import("std");
pub fn main() !void {
var br = std.io.bufferedReader(std.io.getStdIn().reader());
var bw = std.io.bufferedWriter(std.io.getStdOut().writer());
const in = br.reader();
const out = bw.writer();
defer bw.flush() catch {};
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const alloc = arena.allocator();
var input = std.ArrayList(u8).init(alloc);
try in.readUntilDelimiterArrayList(&input, '\n', std.math.maxInt(usize));
try out.print("{s}\n", .{input.items});
try out.print("{}\n", .{input.items.len});
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}
When running the program, it works as expected.
However stepping through the same program in the debugger, I get a different output.
Here is a picture of some of the variables in the middle of a debug run.
It seems that the debugger is replacing the windows "\n" with the mac "\r", as well as printing an extra hello somewhere.
Below is the output of another debug run when I changed the code to look for "\r" instead of "\n"
I also did a normal run where the code is looking for "\r" as the delimiter, and signaled end of file with ctrl-d which resulted in the following (expected) error.
I also have a different, but similar, project that can't debug at all as it just hangs on trying to connect to the debugger. However I don't know the steps to reproduce yet as this bug distracted me first.