Skip to content

Silent overflow when parsing some 78-digit decimal numbers as uint256. #343

@m-alvarez

Description

@m-alvarez

The overflow checking code when parsing decimal numbers is not strict enough and some inputs cause silent overflow. For example, the number below is parsed as 9.

#include <iostream>
#include "./intx/include/intx/intx.hpp"

int main() {
    const auto *const bad =
         "115792089237316195423570985008687907853269984665640564039457584007913129639945";
    auto const bad_num = intx::from_string<intx::uint256>(bad);
    std::cout << bad << std::endl;
    std::cout << intx::to_string(bad_num) << std::endl;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions