summary refs log tree commit diff stats
path: root/lib/std
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-06-22 03:19:30 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-06-22 03:19:30 +0200
commitcc11aa9698e6537fd412bb64a3f99393bc51c90d (patch)
tree05d4287a6e0deb074aab7463443e52af0d40dbfd /lib/std
parent2dab490ec10f8aa0b7f8c0001bcef522747346ab (diff)
downloadNim-cc11aa9698e6537fd412bb64a3f99393bc51c90d.tar.gz
varints module: critical bugfix
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/varints.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/std/varints.nim b/lib/std/varints.nim
index bfc1945fe..483d5c96c 100644
--- a/lib/std/varints.nim
+++ b/lib/std/varints.nim
@@ -19,7 +19,7 @@ proc readVu64*(z: openArray[byte]; pResult: var uint64): int =
     return 1
   if z[0] <= 248:
     if z.len < 2: return 0
-    pResult = (uint64 z[0] - 241) * 256 + uint64 z[1] + 240
+    pResult = (uint64 z[0] - 241) * 256 + z[1].uint64 + 240
     return 2
   if z.len < int(z[0]-246): return 0
   if z[0] == 249:
@@ -135,6 +135,13 @@ when isMainModule:
     if encodeZigzag(decodeZigzag(test)) != test:
       echo "Failure for ", test, " ", encodeZigzag(decodeZigzag(test)), " ", decodeZigzag(test)
 
+  for test in 0u64..300u64:
+    let wrLen = writeVu64(dest, test)
+    let rdLen = readVu64(dest, got)
+    assert wrLen == rdLen
+    if got != test:
+      echo "BUG! expected: ", test, " got: ", got, " z0: ", dest[0]
+
   # check this also works for floats:
   for test in [0.0, 0.1, 2.0, +Inf, Nan, NegInf]:
     let t = cast[uint64](test)