Skip to content

Commit a483a1d

Browse files
committed
test.cpp: check for existence before opening file
1 parent 4f6415f commit a483a1d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz
104104
{
105105
const std::string tmpfile = writeFile(code, size, filename);
106106
std::ifstream fin(tmpfile);
107+
if (!fin.is_open())
108+
throw std::runtime_error("could not open " + tmpfile);
107109
simplecpp::TokenList tokenList(fin, filenames, tmpfile, outputList);
108110
remove(tmpfile.c_str());
109111
return tokenList;
@@ -112,6 +114,9 @@ static simplecpp::TokenList makeTokenListFromFstream(const char code[], std::siz
112114
static simplecpp::TokenList makeTokenListFromFile(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename, simplecpp::OutputList *outputList)
113115
{
114116
const std::string tmpfile = writeFile(code, size, filename);
117+
std::ifstream fin(tmpfile);
118+
if (!fin.is_open())
119+
throw std::runtime_error("could not open " + tmpfile);
115120
simplecpp::TokenList tokenList(tmpfile, filenames, outputList);
116121
remove(tmpfile.c_str());
117122
return tokenList;

0 commit comments

Comments
 (0)