From 47318febd5e82f54963eb9207b786d44cf713343 Mon Sep 17 00:00:00 2001 From: "U-olece-PC\\olece" Date: Wed, 17 Feb 2016 10:07:06 +0100 Subject: [PATCH] Added NULL check for getenv in MSYS2 --- src/config.cc | 12 ++++++++---- src/source_clang.cc | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/config.cc b/src/config.cc index 212ec56..aa5c7c1 100644 --- a/src/config.cc +++ b/src/config.cc @@ -28,10 +28,14 @@ Config::Config() { } #ifdef _WIN32 - terminal.msys2_mingw_path=boost::filesystem::path(std::getenv("WD")).parent_path().parent_path().parent_path(); - std::string msystem=std::getenv("MSYSTEM"); - std::transform(msystem.begin(), msystem.end(), msystem.begin(), ::tolower); - terminal.msys2_mingw_path/=msystem; + auto env_WD=std::getenv("WD"); + auto env_MSYSTEM=std::getenv("MSYSTEM"); + if(env_WD!=NULL && env_MSYSTEM!=NULL) { + terminal.msys2_mingw_path=boost::filesystem::path(env_WD).parent_path().parent_path().parent_path(); + std::string msystem=env_MSYSTEM; + std::transform(msystem.begin(), msystem.end(), msystem.begin(), ::tolower); + terminal.msys2_mingw_path/=msystem; + } #endif } diff --git a/src/source_clang.cc b/src/source_clang.cc index a8397b6..2130993 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -200,7 +200,8 @@ std::vector Source::ClangViewParse::get_compilation_commands() { arguments.emplace_back("-I/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1"); //Added for OS X 10.11 #endif #ifdef _WIN32 - arguments.emplace_back("-I"+(Config::get().terminal.msys2_mingw_path/"lib/clang"/clang_version/"include").string()); + if(!Config::get().terminal.msys2_mingw_path.empty()) + arguments.emplace_back("-I"+(Config::get().terminal.msys2_mingw_path/"lib/clang"/clang_version/"include").string()); #endif } arguments.emplace_back("-fretain-comments-from-system-headers");