diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index 4d7963ef..3117fa81 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -59,11 +59,11 @@ namespace Exiv2 // free functions /*! @brief Return the value of environmental variable. - @param var The name of environmental variable. + @param[in] var The name of environmental variable. Must be a member of the enumeration @ref EnVar. @return the value of environmental variable. If it's empty, the default value is returned. @throws std::out_of_range when an unexpected EnVar is given as input. */ - EXIV2API std::string getEnv(EnVar var); + EXIV2API std::string getEnv(int env_var); /*! @brief Encode the input url. @@ -204,4 +204,4 @@ namespace Exiv2 } // namespace Exiv2 -#endif // #ifndef FUTILS_HPP_ \ No newline at end of file +#endif // #ifndef FUTILS_HPP_ diff --git a/src/futils.cpp b/src/futils.cpp index f2695132..d0d2c067 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -60,12 +60,13 @@ namespace Exiv2 { const char* ENVARKEY[] = {"EXIV2_HTTP_POST", "EXIV2_TIMEOUT"}; //!< @brief request keys for http exiv2 handler and time-out // ***************************************************************************** // free functions - std::string getEnv(EnVar var) + std::string getEnv(int env_var) { - if (var < envHTTPPOST || var > envTIMEOUT) { + // this check is relying on undefined behavior and might not be effective + if (env_var < envHTTPPOST || env_var > envTIMEOUT) { throw std::out_of_range("Unexpected env variable"); } - return getenv(ENVARKEY[var]) ? getenv(ENVARKEY[var]) : ENVARDEF[var]; + return getenv(ENVARKEY[env_var]) ? getenv(ENVARKEY[env_var]) : ENVARDEF[env_var]; } /// @brief Convert an integer value to its hex character.