Tomohiro
53782b1404
Fix parseBiggestUInt to detect overflow ( #24649 )
...
With some inputs larger than `BiggestUInt.high`, `parseBiggestUInt` proc
in `parseutils.nim` fails to detect overflow and returns random value.
This is because `rawParseUInt` try to detects overflow with `if prev >
res:` but it doesn't detects the overflow from multiplication.
It is possible that `x *= 10` causes overflow and resulting value is
larger than original value.
Here is example values larger than `BiggestUInt.high` but
`parseBiggestUInt` returns without detecting overflow:
```
22751622367522324480000000
41404969074137497600000000
20701551093035827200000000000000000
22546225502460313600000000000000000
204963831854661632000000000000000000
```
Following code search for values larger than `BiggestUInt.high` and
`parseBiggestUInt` cannot detect overflow:
```nim
import std/[strutils]
const
# Increase this to extend search range
NBits = 34'u
NBitsMax1 = 1'u shl NBits
NBitsMax = NBitsMax1 - 1'u
# Increase this when there are too many results and want to see only larger result.
MinMultiply10 = 14
var nfound = 0
for i in (NBitsMax div 10'u + 1'u) .. NBitsMax:
var
x = i
n10 = 0
for j in 0 ..< NBits:
let px = x
x = (x * 10'u) and NBitsMax
if x < px:
break
inc n10
if n10 >= MinMultiply10:
echo "i = ", i
echo "uint: ", (i shl (64'u - NBits)), '0'.repeat n10
inc nfound
if nfound > 15:
break
echo "found: ", nfound
```
(cherry picked from commit 95b1dda1db )
2025-01-27 08:51:04 +01:00
..
2023-04-21 15:37:58 +02:00
2022-04-13 11:53:02 +02:00
2023-05-30 21:29:38 +02:00
2019-04-05 15:27:04 +02:00
2022-09-23 13:05:05 +02:00
2022-10-24 15:24:51 +02:00
2022-09-27 20:06:23 +02:00
2017-09-16 19:09:44 +01:00
2020-03-30 13:45:32 +02:00
2018-11-26 10:28:44 +01:00
2018-10-28 13:34:57 +01:00
2022-09-27 20:06:23 +02:00
2022-09-01 17:52:13 +02:00
2020-11-13 16:15:13 +08:00
2022-09-27 20:06:23 +02:00
2022-09-27 20:06:23 +02:00
2022-10-01 22:35:09 +02:00
2024-04-17 10:57:32 +02:00
2023-06-21 12:19:40 +02:00
2023-05-23 09:39:44 +02:00
2024-04-18 09:01:14 +02:00
2023-04-03 05:22:31 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2024-04-23 06:57:55 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2021-01-07 19:16:26 +01:00
2023-06-29 10:51:18 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-05-23 08:59:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2022-12-06 22:37:16 +08:00
2022-12-06 22:37:16 +08:00
2022-09-29 12:16:42 +02:00
2023-05-11 10:23:52 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-06 06:54:07 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-05-21 18:51:02 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2022-10-22 13:42:46 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-25 00:01:08 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2020-03-20 17:11:39 +01:00
2020-03-20 17:11:39 +01:00
2022-09-27 20:06:23 +02:00
2022-09-27 20:06:23 +02:00
2024-06-30 07:28:27 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2020-11-20 08:07:51 +01:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2022-09-27 20:06:23 +02:00
2023-04-11 21:20:20 +02:00
2018-11-23 11:58:28 +01:00
2018-12-11 21:23:21 +01:00
2023-04-21 15:37:58 +02:00
2018-11-23 11:58:28 +01:00
2023-05-10 11:06:14 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2021-10-24 11:51:57 +02:00
2023-12-14 17:48:55 +01:00
2024-04-18 10:33:14 +02:00
2023-06-20 13:04:34 +02:00
2022-09-27 20:06:23 +02:00
2023-02-15 17:41:28 +01:00
2018-11-23 11:58:28 +01:00
2022-09-27 20:06:23 +02:00
2022-09-27 20:06:23 +02:00
2018-11-23 11:58:28 +01:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2024-05-23 09:02:25 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-11-29 06:40:28 +01:00
2022-11-16 16:35:20 +01:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-08-24 09:44:16 +02:00
2022-10-12 15:15:21 +02:00
2023-04-21 15:37:58 +02:00
2024-04-18 10:30:40 +02:00
2023-04-21 15:37:58 +02:00
2024-04-17 09:36:23 +02:00
2023-04-21 15:37:58 +02:00
2022-01-17 13:06:31 +01:00
2023-05-11 10:23:52 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2025-01-27 08:51:04 +01:00
2024-08-19 09:23:43 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-09 16:03:28 +02:00
2022-09-27 20:06:23 +02:00
2024-04-17 09:34:15 +02:00
2023-06-06 06:54:07 +02:00
2023-06-06 06:54:07 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-06 06:54:07 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-04-17 09:34:31 +02:00
2020-10-18 12:57:13 -04:00
2023-04-21 15:37:58 +02:00
2023-06-28 22:38:54 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-13 12:50:43 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-12-06 22:37:16 +08:00
2023-04-21 15:37:58 +02:00
2023-05-11 10:23:52 +02:00
2020-10-05 12:00:06 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-21 08:52:33 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-04-22 10:22:28 +02:00
2023-05-02 11:28:52 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-06 06:54:07 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2024-04-18 08:59:51 +02:00
2024-04-27 20:00:30 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-09-13 10:22:36 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2020-11-10 09:23:58 +08:00
2022-09-27 20:06:23 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-06-26 15:07:42 +02:00
2024-05-23 08:57:27 +02:00
2022-04-13 11:53:02 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2020-07-14 13:14:32 +02:00
2023-04-21 15:37:58 +02:00
2018-05-28 05:24:04 +03:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-06-08 08:02:57 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-12-16 15:11:03 +01:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2022-09-27 20:06:23 +02:00