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 Mar 14, 2023
1 parent e8c1fd9 commit 1dc1258
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

#include "simplecpp.h"

#include <iostream>
#include <limits>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <vector>
#include "simplecpp.h"

enum Input {
Stringstream,
Expand Down Expand Up @@ -109,6 +111,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 @@ -117,6 +121,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 1dc1258

Please sign in to comment.