File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 27
27
28
28
using llvm::cast;
29
29
30
+ #include < climits>
30
31
#include < iostream>
31
32
32
33
namespace swift {
@@ -45,18 +46,17 @@ class MetadataSource {
45
46
const std::string::const_iterator &end,
46
47
unsigned &result) {
47
48
auto begin = it;
48
- while (it != end) {
49
- if (*it >= ' 0' && *it <= ' 9' )
50
- ++it;
51
- else
52
- break ;
53
- }
49
+ for (; it < end && *it >= ' 0' && *it <= ' 9' ; ++it)
50
+ ;
51
+
52
+ if (std::distance (begin, it) == 0 )
53
+ return false ;
54
54
55
- std::string natural ( begin, it );
56
- if (natural. empty () )
55
+ long int decoded = std::strtol (&* begin, nullptr , 10 );
56
+ if ((decoded == LONG_MAX || decoded == LONG_MIN) && errno == ERANGE )
57
57
return false ;
58
58
59
- result = std::atoi (natural. c_str () );
59
+ result = static_cast < unsigned >(decoded );
60
60
return true ;
61
61
}
62
62
You can’t perform that action at this time.
0 commit comments