From 9de10ee515169627c22b4e8e9df3f0b5ed290cf8 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 14 Mar 2023 22:18:02 +0100 Subject: [PATCH] test.cpp: check for existence before opening file --- test.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.cpp b/test.cpp index 842134a3..b1cd5f03 100644 --- a/test.cpp +++ b/test.cpp @@ -117,6 +117,8 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz { const std::string tmpfile = writeFile(code, size, filename); std::ifstream fin(tmpfile); + if (!fin.is_open()) + throw std::runtime_error("could not open " + tmpfile); simplecpp::TokenList tokenList(fin, filenames, tmpfile, outputList); remove(tmpfile.c_str()); return tokenList; @@ -125,6 +127,9 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz static simplecpp::TokenList makeTokenListFromFile(const char code[], std::size_t size, std::vector &filenames, const std::string &filename, simplecpp::OutputList *outputList) { const std::string tmpfile = writeFile(code, size, filename); + std::ifstream fin(tmpfile); + if (!fin.is_open()) + throw std::runtime_error("could not open " + tmpfile); simplecpp::TokenList tokenList(tmpfile, filenames, outputList); remove(tmpfile.c_str()); return tokenList;