mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
critbits: don't rely on terminating zero
This commit is contained in:
@@ -74,8 +74,9 @@ proc rawInsert[T](c: var CritBitTree[T], key: string): Node[T] =
|
||||
var newByte = 0
|
||||
block blockX:
|
||||
while newbyte < key.len:
|
||||
if newbyte >= it.key.len or it.key[newbyte] != key[newbyte]:
|
||||
newotherbits = it.key[newbyte].ord xor key[newbyte].ord
|
||||
let ch = if newbyte < it.key.len: it.key[newbyte] else: '\0'
|
||||
if ch != key[newbyte]:
|
||||
newotherbits = ch.ord xor key[newbyte].ord
|
||||
break blockX
|
||||
inc newbyte
|
||||
if newbyte < it.key.len:
|
||||
@@ -85,7 +86,7 @@ proc rawInsert[T](c: var CritBitTree[T], key: string): Node[T] =
|
||||
while (newOtherBits and (newOtherBits-1)) != 0:
|
||||
newOtherBits = newOtherBits and (newOtherBits-1)
|
||||
newOtherBits = newOtherBits xor 255
|
||||
let ch = it.key[newByte]
|
||||
let ch = if newByte < it.key.len: it.key[newByte] else: '\0'
|
||||
let dir = (1 + (ord(ch) or newOtherBits)) shr 8
|
||||
|
||||
var inner: Node[T]
|
||||
|
||||
Reference in New Issue
Block a user