mcst-linux-kernel/patches-2024.06.26/sloccount-2.26/0001-Add-check-for-fopen.patch

62 lines
1.4 KiB
Diff

From d3bcc8ce65eecdaf2038f124c04fadbd237f1282 Mon Sep 17 00:00:00 2001
Date: Wed, 20 Dec 2017 19:01:13 +0300
Subject: [PATCH] Add check for fopen
---
c_count.c | 5 +++++
ml_count.c | 5 +++++
php_count.c | 5 +++++
3 files changed, 15 insertions(+)
diff --git a/c_count.c b/c_count.c
index 8581e55..567f746 100644
--- a/c_count.c
+++ b/c_count.c
@@ -162,6 +162,11 @@ void count_file(char *filename) {
FILE *stream;
stream = fopen(filename, "r");
+ if (!stream) {
+ sloc = 0;
+ fprintf(stderr, "Error: Cannot open %s\n", filename);
+ return;
+ }
line_number = 1;
sloc = sloc_count(filename, stream);
total_sloc += sloc;
diff --git a/ml_count.c b/ml_count.c
index dc18f35..fdd5c2c 100644
--- a/ml_count.c
+++ b/ml_count.c
@@ -146,6 +146,11 @@ void count_file(char *filename) {
FILE *stream;
stream = fopen(filename, "r");
+ if (!stream) {
+ sloc = 0;
+ fprintf(stderr, "Error: Cannot open %s\n", filename);
+ return;
+ }
line_number = 1;
sloc = sloc_count(filename, stream);
total_sloc += sloc;
diff --git a/php_count.c b/php_count.c
index ee7ce10..0233c3e 100644
--- a/php_count.c
+++ b/php_count.c
@@ -270,6 +270,11 @@ void count_file(char *filename) {
FILE *stream;
stream = fopen(filename, "r");
+ if (!stream) {
+ sloc = 0;
+ fprintf(stderr, "Error: Cannot open %s\n", filename);
+ return;
+ }
line_number = 0;
init_input(stream);
sloc = sloc_count(filename, stream);
--
2.16.4