Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Updated sqlite to 3.40.1
* Updated zlib to 1.2.13

* Fixed crash writing to the null device on Windows
* Fixed SSL socket non blocking handshake throwing an exception on 64bit Windows
* Fixed Windows 64bit architecture detection
* Fixed critial error handler returning the wrong callstack
Expand Down
5 changes: 4 additions & 1 deletion src/hx/libs/std/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ int _hx_std_file_write( Dynamic handle, Array<unsigned char> s, int p, int n )

hx::AutoGCFreeZone zone;
#ifdef HX_WINDOWS
if (_isatty(_fileno(f->io))) {
// _isatty is true for ANY character device - NUL, a serial port, a printer - and none of
// those accept WriteConsoleW. Only a real console has a console mode.
DWORD console_mode;
if (_isatty(_fileno(f->io)) && GetConsoleMode((HANDLE)_get_osfhandle(_fileno(f->io)), &console_mode)) {
fflush(f->io);
HANDLE win_handle = (HANDLE)_get_osfhandle(_fileno(f->io));
static const int MAX_BUFFER_SIZE = 8192;
Expand Down
13 changes: 13 additions & 0 deletions test/regression/NulDeviceWrite/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// The null device is a character device, so _isatty reports it as a tty. file_write used that as
// its test for a console and called WriteConsoleW, which only accepts a console handle; the failure
// threw from inside a GC-free zone and took the process down instead of reporting an error.
function main() {
final nul = Sys.systemName() == "Windows" ? "NUL" : "/dev/null";

final out = sys.io.File.write(nul);
out.writeString("written to the null device\n");
out.flush();
out.close();

Sys.println("ok");
}
2 changes: 2 additions & 0 deletions test/regression/NulDeviceWrite/build.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-cpp bin
-m Main
1 change: 1 addition & 0 deletions test/regression/NulDeviceWrite/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok
Loading