Commit 435c8ad703

Andrew Kelley <andrew@ziglang.org>
2020-10-27 00:06:14
non-hacky workaround for the empty file bug
See #3328
1 parent 1ce0994
Changed files (2)
src/stage1/analyze.cpp
@@ -8052,13 +8052,10 @@ not_integer:
 }
 
 Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) {
-    size_t len = 0xAA;
+    size_t len;
     const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len);
-    if (len == 0) {
-        // File exists but is empty (otherwise it would be 0xAA)
-    } else if (contents == nullptr) {
+    if (contents == nullptr)
         return ErrorFileNotFound;
-    }
     buf_init_from_mem(contents_buf, contents, len);
     return ErrorNone;
 }
src/stage1.zig
@@ -428,5 +428,7 @@ export fn stage2_fetch_file(
     const max_file_size = std.math.maxInt(u32);
     const contents = comp.stage1_cache_manifest.addFilePostFetch(file_path, max_file_size) catch return null;
     result_len.* = contents.len;
+    // TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475
+    if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1);
     return contents.ptr;
 }