From c3bee1c9ce143625ef41a5fa713acab23b2d9688 Mon Sep 17 00:00:00 2001 From: nashe Date: Sun, 4 Jun 2017 01:06:33 +0200 Subject: [PATCH] Correctly handle fopen() return value --- main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.c b/main.c index d703030..4055294 100644 --- a/main.c +++ b/main.c @@ -3,6 +3,7 @@ Released under the GNU GPL v3. See LICENSE for details. */ #define _XOPEN_SOURCE +#include #include #include #include @@ -56,6 +57,10 @@ int main (int argc, char** argv) { } else if (optind < argc) { if (strcmp (argv [optind], "-") != 0) op.f = fopen (argv[optind], "rb"); + if (op.f == NULL) { + fprintf (stderr, "Impossible to open the file %s: %s\n", argv[optind], strerror(errno)); + return 1; + } } if (op.d) { -- 2.39.3