Skip to content

Commit

Permalink
test.cpp: check for existence before opening file
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 26, 2023
1 parent e4c2083 commit 9de10ee
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<std::string> &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;
Expand Down

0 comments on commit 9de10ee

Please sign in to comment.