You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
If you have custom exceptions, maybe the solution would be to
try{
intValue = std::stoi(str);
} catch(std::out_of:range&) {
throwwinget::exception("We cannot handle values that huge for count"); // If we have custom winget exceptions
}
if (intValue < 0)
throwwinget::exception("Count must always be positive");
And probably added unit tests to check for the same
Activity
pratikpc commentedon Oct 7, 2021
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
denelon commentedon Oct 7, 2021
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.
pratikpc commentedon Oct 8, 2021
Demitrius Nelon (@denelon) I believe the same
If you have custom exceptions, maybe the solution would be to
And probably added unit tests to check for the same
jedieaston commentedon Oct 8, 2021
This was resolved by #1564 (GitHub can't attach multiple issue numbers to a single "Resolves").