2018-03-20 16:31:34 +00:00
|
|
|
import ./mem_corrupt_bug_add,
|
|
|
|
./mem_corrupt_bug_mul
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
when isMainModule:
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
import typetraits
|
2018-03-20 16:31:34 +00:00
|
|
|
import ./mem_corrupt_bug_convert
|
2018-02-15 22:28:31 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
let a = toMpUint(10'u32)
|
2018-02-15 22:28:31 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
echo "a: " & $a
|
|
|
|
echo "a+a: " & $(a+a)
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
let z = a * a
|
2018-03-20 15:12:42 +00:00
|
|
|
echo "a * a: " & $z # How did the result value change?
|
|
|
|
echo "a * a type: " & $z.type.name
|
2018-02-16 08:22:23 +00:00
|
|
|
|
2018-03-20 15:14:31 +00:00
|
|
|
# Compile without release: memory corruption
|
|
|
|
# In release: no corruption
|
|
|
|
# Comment out the "naiveMul" in mul_impl: no corruption
|
2018-03-20 15:12:42 +00:00
|
|
|
echo "Is memory corrupted: " & $(z != toMpUint(100'u32))
|
2018-03-20 15:16:09 +00:00
|
|
|
|
|
|
|
# Output on my machine
|
|
|
|
#
|
|
|
|
# a: (lo: 10, hi: 0)
|
|
|
|
# +: (lo: 20, hi: 0)
|
|
|
|
# a+a: (lo: 20, hi: 0)
|
|
|
|
# naiveMul cast16:(lo: 100, hi: 0)
|
|
|
|
# naiveMul cast16:(lo: 0, hi: 0)
|
|
|
|
# naiveMul cast16:(lo: 0, hi: 0)
|
|
|
|
# +: (lo: 0, hi: 0)
|
|
|
|
# Within `*` result: (lo: 100, hi: 0)
|
2018-03-20 16:31:34 +00:00
|
|
|
# Within `*` result type: MpUint[32]
|
|
|
|
# a * a: (lo: 100, hi: 3924)
|
2018-03-20 15:16:09 +00:00
|
|
|
# a * a type: MpUint[32]
|
|
|
|
# Is memory corrupted: true
|