Skip to content

Commit

Permalink
Msvc warn fix (#20)
Browse files Browse the repository at this point in the history
* Remove windows warning, use secure getenv

* Fix typo in last commit

* Fix typo in windows version

* Fix another typo in windows version

* Fixing error, dropping warn suppression
  • Loading branch information
henryiii authored Jun 5, 2017
1 parent 1c1a622 commit 0da8fa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 0da8fa9

Please sign in to comment.