Skip to content

stoi argument out of range #1549

Closed

Description

PS C:\Users\denelon> winget search 123 -n 853837271271781839344
An unexpected error occurred while executing the command:
stoi argument out of range

Activity

  1. added
    Issue-Bug
    on Oct 4, 2021
  2. ghost added
    Needs-Triage
    on Oct 4, 2021
  3. removed
    Needs-Triage
    on Oct 4, 2021
  4. pratikpc commented on Oct 7, 2021

    @pratikpc

    For larger integers, we would have to switch to a larger data type.

    Unfortunately for the value in question, log2(853837271271781839344) is approx 69.5 so we would need a 128 bit integer to store it but no sto* function supports 128 bit integers.

    However, to handle larger than INT_MAX numbers, we could switch to long long and stoll

    We could also use unsigned which will add support for even bigger numbers but a check for input with negative numbers will be required. (Edit:- However checks for negative numbers would be required to be added anyways under #1548. If we switch to unsigned, checks for negative would however have to be made before input is provided to stou*)

    Maybe catching the error and displaying that we only support numbers smaller than std::numeric_limits::max() values?

    Reference
    https://stackoverflow.com/questions/29931827/stoi-causes-out-of-range-error

  5. denelon commented on Oct 7, 2021

    @denelon
    CollaboratorAuthor

    Pratik Chowdhury (@pratikpc) thanks for the pointer. We may need to use that in a couple of other places. I think in this case we should do a check and provide a better message to the user. Requesting that many results in a search seems an unlikely use case to me.

  6. pratikpc commented on Oct 8, 2021

    @pratikpc

    Demitrius Nelon (@denelon) I believe the same

    If you have custom exceptions, maybe the solution would be to

    try{
                    intValue = std::stoi(str);
    } catch(std::out_of:range&) {
                    throw winget::exception("We cannot handle values that huge for count"); // If we have custom winget exceptions
    }
    if (intValue < 0)
                    throw winget::exception("Count must always be positive");

    And probably added unit tests to check for the same

  7. jedieaston commented on Oct 8, 2021

    @jedieaston
    Contributor

    This was resolved by #1564 (GitHub can't attach multiple issue numbers to a single "Resolves").

  8. moved this from To Do to Done in WinGeton Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Bug

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions