MCPcopy Create free account
hub / github.com/WebAssembly/wabt / ParseInt

Function ParseInt

src/literal.cc:718–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

716
717template <typename U>
718Result ParseInt(const char* s,
719 const char* end,
720 U* out,
721 ParseIntType parse_type) {
722 using S = typename std::make_signed<U>::type;
723 uint64_t value;
724 bool has_sign = false;
725 if (*s == '-' || *s == '+') {
726 if (parse_type == ParseIntType::UnsignedOnly) {
727 return Result::Error;
728 }
729 if (*s == '-') {
730 has_sign = true;
731 }
732 s++;
733 }
734 CHECK_RESULT(ParseUint64(s, end, &value));
735
736 if (has_sign) {
737 // abs(INTN_MIN) == INTN_MAX + 1.
738 if (value > static_cast<uint64_t>(std::numeric_limits<S>::max()) + 1) {
739 return Result::Error;
740 }
741 value = std::numeric_limits<U>::max() - value + 1;
742 } else {
743 if (value > static_cast<uint64_t>(std::numeric_limits<U>::max())) {
744 return Result::Error;
745 }
746 }
747 *out = static_cast<U>(value);
748 return Result::Ok;
749}
750
751Result ParseInt8(const char* s,
752 const char* end,

Callers 3

ParseInt8Function · 0.85
ParseInt16Function · 0.85
ParseInt32Function · 0.85

Calls 1

ParseUint64Function · 0.70

Tested by

no test coverage detected