configuration: trim MPD_PORT value before passing it to lexical_cast

This commit is contained in:
Andrzej Rybczak
2016-11-16 11:19:41 +01:00
parent 8dde3944ee
commit e3bb8aaad5

View File

@@ -19,6 +19,7 @@
***************************************************************************/
#include <algorithm>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/program_options.hpp>
#include <iostream>
@@ -178,8 +179,9 @@ bool configure(int argc, char **argv)
Mpd.SetHostname(env_host);
if (env_port != nullptr)
{
auto trimmed_env_port = boost::trim_copy<std::string>(env_port);
try {
Mpd.SetPort(boost::lexical_cast<int>(env_port));
Mpd.SetPort(boost::lexical_cast<int>(trimmed_env_port));
} catch (boost::bad_lexical_cast &) {
throw std::runtime_error("MPD_PORT environment variable ("
+ std::string(env_port)