Skip to content

Commit

Permalink
Fix #335: object lifetime issue when reporting error (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Feb 2, 2024
1 parent ea78f9a commit 1b29369
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ class StdIStream : public simplecpp::TokenList::Stream {
class FileStream : public simplecpp::TokenList::Stream {
public:
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
EXPLICIT FileStream(const std::string &filename)
EXPLICIT FileStream(const std::string &filename, std::vector<std::string> &files)
: file(fopen(filename.c_str(), "rb"))
, lastCh(0)
, lastStatus(0)
{
if (!file) {
const std::vector<std::string> location;
throw simplecpp::Output(location, simplecpp::Output::FILE_NOT_FOUND, "File is missing: " + filename);
files.push_back(filename);
throw simplecpp::Output(files, simplecpp::Output::FILE_NOT_FOUND, "File is missing: " + filename);
}
init();
}
Expand Down Expand Up @@ -447,7 +447,7 @@ simplecpp::TokenList::TokenList(const std::string &filename, std::vector<std::st
{
try
{
FileStream stream(filename);
FileStream stream(filename, filenames);
readfile(stream,filename,outputList);
}
catch(const simplecpp::Output & e) // TODO handle extra type of errors
Expand Down
2 changes: 1 addition & 1 deletion simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace simplecpp {
EXPLICIT_INCLUDE_NOT_FOUND,
FILE_NOT_FOUND
} type;
explicit Output(const std::vector<std::string> &files, Output::Type id, const std::string & errMsg ) : type(id), location(files), msg(errMsg) {}
explicit Output(const std::vector<std::string>& files, Type type, const std::string& msg) : type(type), location(files), msg(msg) {}
Location location;
std::string msg;
};
Expand Down

0 comments on commit 1b29369

Please sign in to comment.