[Boost-bugs] [Boost C++ Libraries] #7018: operations_test.cpp does not correctly use setenv

Subject: [Boost-bugs] [Boost C++ Libraries] #7018: operations_test.cpp does not correctly use setenv
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-06-22 19:28:44


#7018: operations_test.cpp does not correctly use setenv
-------------------------------------------------------------+--------------
 Reporter: Daniel Krügler <daniel.kruegler@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.49.0 | Severity: Problem
 Keywords: |
-------------------------------------------------------------+--------------
 The constructor of guarded_env_var::previous_value never sets the member
 variable m_name but does instead set the member m_string with the
 environment name. This means that the destructor of previous_value always
 calls unsetenv or setenv with an empty name string.

 The required fix seems to be to replace in line 1711
 {{{
       : m_string(name)
 }}}
 by
 {{{
       : m_name(name)
 }}}
 As I side note I would like to remark that the return values of the
 Windows emulations between line 62 and 75
 {{{
 inline int setenv(const char* name, const fs::path::value_type* val, int)
 {
   return SetEnvironmentVariableW(convert(name).c_str(), val);
 }

 inline int setenv(const char* name, const char* val, int)
 {
   return SetEnvironmentVariableW(convert(name).c_str(),
 convert(val).c_str());
 }

 inline int unsetenv(const char* name)
 {
   return SetEnvironmentVariableW(convert(name).c_str(), 0);
 }
 }}}
 are inverted versus the POSIX functions, ::SetEnvironmentVariableW returns
 0 on failure and non-zero on success. While a proper fix is easy to
 realize along the lines of
 {{{
 inline int setenv(const char* name, const fs::path::value_type* val, int)
 {
   return SetEnvironmentVariableW(convert(name).c_str(), val) ? 0 : -1;
 }

 inline int setenv(const char* name, const char* val, int)
 {
   return SetEnvironmentVariableW(convert(name).c_str(),
 convert(val).c_str()) ? 0 : -1;
 }

 inline int unsetenv(const char* name)
 {
   return SetEnvironmentVariableW(convert(name).c_str(), 0) ? 0 : -1;
 }
 }}}
 a much simpler fix would be to define them as void functions because the
 return values are never tested.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7018>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC