Skip to content

Commit

Permalink
Add a check when feeding a directory path to readFile (#188)
Browse files Browse the repository at this point in the history
* Add a check when feeding a directory path to readFile
  • Loading branch information
NadirRoGue authored Mar 31, 2022
1 parent 0f8927a commit 4b11c8d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

#include "utils.h"

#include <fstream>
#include "../extlib/filesystem.hpp"

#include <fstream>

std::string readFile(const std::string& path) {
namespace fs = ghc::filesystem;

if (!fs::is_regular_file(path))
throw std::runtime_error("Path `" + path + "` is not a file");

std::ifstream file(path);

if (file.fail())
Expand Down

0 comments on commit 4b11c8d

Please sign in to comment.