authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-07-01 14:15:58+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-07-02 10:35:44+02:00
logb5badd112288b528d75085d82d5f7f1b109e87dc
treeb4f9cd29b0464457a4fa62fb4ba369e8da3938b1
parent64bd134818b77ba56deb613112ec8cdb0c967703

Fix memory corruption in Dir.Iterator test


1 files changed, 10 insertions(+), 4 deletions(-)

lib/std/fs/test.zig+10-4
......@@ -5,6 +5,7 @@ const fs = std.fs;
55const mem = std.mem;
66const wasi = std.os.wasi;
77
8const ArenaAllocator = std.heap.ArenaAllocator;
89const Dir = std.fs.Dir;
910const File = std.fs.File;
1011const tmpDir = testing.tmpDir;
......@@ -19,13 +20,18 @@ test "Dir.Iterator" {
1920
2021 try tmp_dir.dir.makeDir("some_dir");
2122
23 var arena = ArenaAllocator.init(testing.allocator);
24 defer arena.deinit();
25
26 var entries = std.ArrayList(Dir.Entry).init(&arena.allocator);
27
2228 // Create iterator.
2329 var iter = tmp_dir.dir.iterate();
24 var entries = std.ArrayList(Dir.Entry).init(testing.allocator);
25 defer entries.deinit();
26
2730 while (try iter.next()) |entry| {
28 try entries.append(entry);
31 // We cannot just store `entry` as on Windows, we're re-using the name buffer
32 // which means we'll actually share the `name` pointer between entries!
33 const name = try mem.dupe(&arena.allocator, u8, entry.name);
34 try entries.append(Dir.Entry{ .name = name, .kind = entry.kind });
2935 }
3036
3137 testing.expect(entries.items.len == 2); // note that the Iterator skips '.' and '..'