[futils] Change signature of getEnv to take an int

While taking an EnVar as the parameter is more clear it has the
disadvantage, that passing anything outside of the range of the
enumeration is undefined behavior. The compiler could then optimize
the range check in getEnv away (perfectly legal due to UB), leading
to buffer overreads.
This commit is contained in:
Dan Čermák
2018-08-24 09:41:04 +02:00
parent e705f1ef5b
commit 9f1a5a1ebb
2 changed files with 7 additions and 6 deletions
+3 -3
View File
@@ -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_
#endif // #ifndef FUTILS_HPP_