Commit 94b0d0e802

Andrew Kelley <andrew@ziglang.org>
2020-05-01 21:13:55
std.progress: handle error from FillConsoleOutputAttribute
I observed this returning an error. Fall back to not doing terminal stuff if an error occurs here. See #5244
1 parent 5418efa
Changed files (1)
lib
lib/std/progress.zig
@@ -145,7 +145,7 @@ pub const Progress = struct {
             if (self.supports_ansi_escape_codes) {
                 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[{}D", .{self.columns_written}) catch unreachable).len;
                 end += (std.fmt.bufPrint(self.output_buffer[end..], "\x1b[0K", .{}) catch unreachable).len;
-            } else if (std.builtin.os.tag == .windows) {
+            } else if (std.builtin.os.tag == .windows) winapi: {
                 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
                 if (windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) != windows.TRUE)
                     unreachable;
@@ -167,7 +167,11 @@ pub const Progress = struct {
                     fill_chars,
                     cursor_pos,
                     &written,
-                ) != windows.TRUE) unreachable;
+                ) != windows.TRUE) {
+                    // Stop trying to write to this file.
+                    self.terminal = null;
+                    break :winapi;
+                }
                 if (windows.kernel32.FillConsoleOutputCharacterA(
                     file.handle,
                     ' ',