Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msvc warn fix #20

Merged
merged 5 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Be moderately paranoid with flags
if(MSVC)
add_definitions("/W4")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
add_definitions("-Wall -Wextra -pedantic")
endif()
Expand Down
22 changes: 19 additions & 3 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,25 @@ class App {
// Get envname options if not yet passed
for(const Option_p &opt : options_) {
if(opt->count() == 0 && opt->envname_ != "") {
char *ename = std::getenv(opt->envname_.c_str());
if(ename != nullptr) {
opt->add_result(std::string(ename));
char *buffer = nullptr;
std::string ename_string;

#ifdef _MSC_VER
// Windows version
size_t sz = 0;
if(_dupenv_s(&buffer, &sz, opt->envname_.c_str()) == 0 && buffer != nullptr) {
ename_string = std::string(buffer);
free(buffer);
}
#else
// This also works on Windows, but gives a warning
buffer = std::getenv(opt->envname_.c_str());
if(buffer != nullptr)
ename_string = std::string(buffer);
#endif

if(!ename_string.empty()) {
opt->add_result(ename_string);
}
}
}
Expand Down