From 9efc71de4f4be9c43c0521dd5f627bbdcc82b78a Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 25 Dec 2020 13:42:09 +0100 Subject: Fix incorrect usage of ferror after fclose Closes #35 --- lolcat.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lolcat.c b/lolcat.c index c300845..5512f17 100644 --- a/lolcat.c +++ b/lolcat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 jaseg +/* Copyright (C) 2020 jaseg * * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * Version 2, December 2004 @@ -205,10 +205,14 @@ int main(int argc, char** argv) cc = -1; if (f) { - fclose(f); - if (ferror(f)) { fwprintf(stderr, L"Error reading input file \"%s\": %s\n", *filename, strerror(errno)); + fclose(f); + return 2; + } + + if (fclose(f)) { + fwprintf(stderr, L"Error closing input file \"%s\": %s\n", *filename, strerror(errno)); return 2; } } -- cgit