Tomohiro
95b1dda1db
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
```
2025-01-25 15:43:40 +01:00
..
2024-09-30 20:54:07 +02:00
2022-04-13 11:53:02 +02:00
2024-11-23 22:01:39 +01: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
2024-12-23 06:08:46 +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
2024-12-25 09:27:12 +01: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
2023-08-10 16:26:23 +08:00
2023-06-21 12:19:40 +02:00
2023-05-23 09:39:44 +02:00
2023-09-30 06:34:14 +02:00
2023-09-21 00:35:48 +02:00
2024-11-23 22:01:39 +01:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2023-10-03 11:00:24 +08:00
2024-04-22 09:44:33 +02:00
2023-04-21 15:37:58 +02:00
2024-11-23 22:01:39 +01: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
2024-04-11 09:14:56 +02:00
2023-04-21 15:37:58 +02:00
2024-05-08 14:53:01 -06: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
2024-11-23 22:01:39 +01:00
2024-11-23 22:01:39 +01: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-06 14:21:55 +02:00
2023-04-21 15:37:58 +02:00
2024-09-03 16:35:04 +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-11-23 22:01:39 +01:00
2022-09-27 20:06:23 +02:00
2022-10-22 13:42:46 +02:00
2024-11-23 22:01:39 +01:00
2024-11-23 22:01:39 +01: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-11-23 22:01:39 +01: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
2024-11-23 22:01:39 +01:00
2022-09-27 20:06:23 +02:00
2024-06-29 20:49:54 +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
2024-11-23 22:01:39 +01:00
2022-09-27 20:06:23 +02:00
2024-10-19 16:40:28 +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
2024-11-23 22:01:39 +01:00
2024-12-23 06:08:46 +01: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
2024-11-23 22:01:39 +01:00
2023-11-26 06:32:32 +01:00
2024-09-22 13:57:03 +02:00
2025-01-09 09:07:59 +01: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-11-30 11:00:33 +01:00
2024-05-10 10:30:24 +02:00
2024-04-03 16:59:35 +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-11-23 22:01:39 +01:00
2023-04-21 15:37:58 +02:00
2022-11-29 06:40:28 +01:00
2024-11-23 22:01:39 +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-11-23 22:01:39 +01:00
2023-04-21 15:37:58 +02:00
2024-09-27 16:36:31 +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
2024-11-02 07:58:19 +01:00
2025-01-25 15:43:40 +01:00
2024-11-23 22:01:39 +01:00
2022-09-27 20:06:23 +02:00
2023-04-21 15:37:58 +02:00
2024-05-31 11:07:48 +02:00
2024-12-12 22:56:41 +01:00
2023-06-09 16:03:28 +02:00
2022-09-27 20:06:23 +02:00
2024-11-23 22:01:39 +01:00
2023-06-06 06:54:07 +02:00
2023-06-06 06:54:07 +02:00
2023-12-15 07:49:07 +01:00
2024-11-23 22:01:39 +01: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-08-04 05:29:48 +02:00
2020-10-18 12:57:13 -04:00
2023-04-21 15:37:58 +02:00
2024-11-23 22:01:39 +01:00
2024-11-25 10:51:03 +01:00
2024-11-23 22:01:39 +01:00
2024-10-19 10:07:00 +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
2024-11-23 22:01:39 +01:00
2022-12-06 22:37:16 +08:00
2023-04-21 15:37:58 +02:00
2024-11-23 22:01:39 +01:00
2020-10-05 12:00:06 +02:00
2022-09-27 20:06:23 +02:00
2023-08-18 16:47:47 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-11-23 22:01:39 +01:00
2024-11-23 22:01:39 +01:00
2024-09-04 09:25:01 +02:00
2024-11-23 22:01:39 +01: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
2024-12-25 09:27:12 +01:00
2024-11-23 22:01:39 +01:00
2024-11-23 22:01:39 +01: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-10-19 16:40:28 +02:00
2024-11-23 22:01:39 +01:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-08-09 10:39:40 +08:00
2024-10-09 18:20:43 +02:00
2024-11-23 22:01:39 +01: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
2024-11-23 22:01:39 +01:00
2024-11-23 22:01:39 +01:00
2022-04-13 11:53:02 +02:00
2023-04-21 15:37:58 +02:00
2024-05-29 06:42:07 +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
2024-09-19 07:19:59 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-11-23 22:01:39 +01:00
2024-07-22 07:11:14 +02:00
2023-04-21 15:37:58 +02:00
2024-08-28 20:44:06 +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
2024-11-23 22:01:39 +01:00
2024-09-09 14:44:49 +02:00
2023-04-21 15:37:58 +02:00
2023-04-21 15:37:58 +02:00
2024-09-19 07:19:59 +02:00
2024-11-23 22:01:39 +01:00