Raise in ParseDouble with empty string or float overflow

Summary:
The check is made more robust by using the `fail` accessor along with
`eof`.

Reviewers: florijan, buda, mislav.bradac, dgleich

Reviewed By: dgleich

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D376
This commit is contained in:
Teon Banek 2017-05-17 14:30:12 +02:00
parent e791e9b660
commit 8d8ef19694

View File

@ -101,11 +101,11 @@ inline std::vector<std::string> Split(const std::string& src,
*/
inline double ParseDouble(const std::string& s) {
// stod would be nicer but it uses current locale so we shouldn't use it.
double t = 0LL;
double t = 0.0;
std::istringstream iss(s);
iss.imbue(std::locale::classic());
iss >> t;
if (!iss.eof()) {
if (iss.fail() || !iss.eof()) {
throw BasicException("Couldn't parse string");
}
return t;