Skip to content

Reflection: use std::strtol instead of std::atoi #3129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions include/swift/Reflection/MetadataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

using llvm::cast;

#include <climits>
#include <iostream>

namespace swift {
Expand All @@ -45,18 +46,17 @@ class MetadataSource {
const std::string::const_iterator &end,
unsigned &result) {
auto begin = it;
while (it != end) {
if (*it >= '0' && *it <= '9')
++it;
else
break;
}
for (; it < end && *it >= '0' && *it <= '9'; ++it)
;

if (std::distance(begin, it) == 0)
return false;

std::string natural(begin, it);
if (natural.empty())
long int decoded = std::strtol(&*begin, nullptr, 10);
if ((decoded == LONG_MAX || decoded == LONG_MIN) && errno == ERANGE)
return false;

result = std::atoi(natural.c_str());
result = static_cast<unsigned>(decoded);
return true;
}

Expand Down