aboutsummaryrefslogtreecommitdiffstats
path: root/mutator-lvl0.cpp
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-02-05 19:48:02 +0000
committerbloodstalker <thabogre@gmail.com>2017-02-05 19:48:02 +0000
commit773bfb0d4d3afc32c675aee9670d3f4f0205b8af (patch)
tree52a7f41785fe13d2fa26356070350078edefd2f8 /mutator-lvl0.cpp
parentfixing (diff)
downloadmutator-773bfb0d4d3afc32c675aee9670d3f4f0205b8af.tar.gz
mutator-773bfb0d4d3afc32c675aee9670d3f4f0205b8af.zip
in case mutator gets a bad header, now it throws an exception instead of just a seg fault.
Diffstat (limited to '')
-rw-r--r--mutator-lvl0.cpp52
1 files changed, 49 insertions, 3 deletions
diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp
index a8c0f52..fffa2e7 100644
--- a/mutator-lvl0.cpp
+++ b/mutator-lvl0.cpp
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#include "mutator_aux.h"
/*standard headers*/
#include <cassert>
+#include <exception>
#include <fstream>
#include <iostream>
#include <regex>
@@ -76,6 +77,26 @@ std::vector<std::string> MacroNameString;
std::vector<std::string> IncludeFileArr;
/**********************************************************************************************************************/
+struct MutExHeaderNotFound : public std::exception
+{
+public:
+ MutExHeaderNotFound(std::string FileName) : FName(FileName) {}
+
+ const char* what () const throw()
+ {
+ const char* OutString = "Header not Found";
+ return OutString;
+ }
+
+ std::string getFileName() const
+ {
+ return FName;
+ }
+
+private:
+ std::string FName;
+};
+/**********************************************************************************************************************/
/*@DEVI-struct for nullstmt*/
struct NullStmtInfo
{
@@ -5473,18 +5494,37 @@ class PPInclusion : public PPCallbacks
public:
explicit PPInclusion (SourceManager *SM) : SM(*SM) {}
+ /*@DEVI-if we dont throw an exception for a bad header inclusion, we wil crash later on since we have InclusionDirective PPCallback.*/
+ virtual bool FileNotFound(StringRef FileName, SmallVectorImpl<char> &RecoveryPath)
+ {
+ throw MutExHeaderNotFound(FileName.str());
+ }
+
virtual void InclusionDirective (SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, \
bool IsAngled, CharSourceRange FileNameRange, const FileEntry* File, \
StringRef SearchPath, StringRef RelativePath, const clang::Module* Imported)
{
- /*@DEVI-not including the correct directory for headers inclusions will make the code crash. the below consition does not prevent that.*/
- if (File->isValid())
+#if defined(__linux__)
+ std::ifstream HeaderABS(SearchPath.str() + "/" + FileName.str());
+ std::ifstream HeaderRel(RelativePath.str() + "/" + FileName.str());
+#elif defined(__MACH__) && defined(__APPLE__)
+ std::ifstream HeaderABS(SearchPath.str() + "/" + FileName.str());
+ std::ifstream HeaderRel(RelativePath.str() + "/" + FileName.str());
+#elif defined(__CYGWIN__) || defined(_WIN32) || defined(_WIN64)
+ std::ifstream HeaderABS(SearchPath.str() + "\\" + FileName.str());
+ std::ifstream HeaderRel(RelativePath.str() + "\\" + FileName.str());
+#else
+ std::ifstream HeaderABS(SearchPath.str() + "/" + FileName.str());
+ std::ifstream HeaderRel(RelativePath.str() + "/" + FileName.str());
+#endif
+
+ if (File->isValid() && (HeaderABS.good() || HeaderRel.good()))
{
#if 0
assert(HashLoc.isValid() && "The SourceLocation for InclusionDirective is invalid.");
#endif
-#if 0
+#if 1
if (IsAngled)
{
size_t singleQPos = FileName.find("\'", 0);
@@ -7386,6 +7426,12 @@ int main(int argc, const char **argv)
JSONDocOUT.CloseReport();
+ try {}
+ catch (MutExHeaderNotFound &E1)
+ {
+ std::cerr << E1.what() << std::endl;
+ }
+
return RunResult;
}
/*last line intentionally left blank.*/