From 2abb57c5b8ff8f3b54134d4f3388de599c25449c Mon Sep 17 00:00:00 2001 From: bung87 Date: Fri, 27 May 2022 10:50:05 +0800 Subject: [PATCH] fix #19600 No error checking on fclose --- lib/std/syncio.nim | 4 +++- tests/misc/t19600.nim | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/misc/t19600.nim diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index eab96254a8973..9354d4d4abcba 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -324,7 +324,9 @@ const proc close*(f: File) {.tags: [], gcsafe.} = ## Closes the file. if not f.isNil: - discard c_fclose(f) + let x = c_fclose(f) + if x < 0: + checkErr(f) proc readChar*(f: File): char {.tags: [ReadIOEffect].} = ## Reads a single character from the stream `f`. Should not be used in diff --git a/tests/misc/t19600.nim b/tests/misc/t19600.nim new file mode 100644 index 0000000000000..3708dac1825e2 --- /dev/null +++ b/tests/misc/t19600.nim @@ -0,0 +1,9 @@ +discard """ + targets: "c cpp" + disabled: "win" + disabled: "osx" + exitcode: 1 + outputsub: "No space left on device" +""" + +writeFile("/dev/full", "hello\n")