remove local variables
Nim doesn't understand the data flow since these functions are exportc there is no hope.
This commit is contained in:
parent
73c3c50bbf
commit
fa8f09e745
|
@ -580,55 +580,39 @@ template mutatorImpl*(target, mutator, typ: untyped) =
|
||||||
buffer: seq[byte] = @[0xf1'u8]
|
buffer: seq[byte] = @[0xf1'u8]
|
||||||
cached: typ
|
cached: typ
|
||||||
|
|
||||||
proc getInput(x: var typ; data: openArray[byte]): lent typ {.nocov, nosan.} =
|
proc getInput(data: openArray[byte]) {.nocov, nosan.} =
|
||||||
if equals(data, buffer):
|
if equals(data, buffer):
|
||||||
result = cached
|
discard
|
||||||
else:
|
else:
|
||||||
var pos = 1
|
var pos = 1
|
||||||
#when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1):
|
reset(cached)
|
||||||
#x = move cached
|
fromData(data, pos, cached)
|
||||||
fromData(data, pos, x)
|
|
||||||
result = x
|
|
||||||
|
|
||||||
proc mgetInput(x: var typ; data: openArray[byte]) =
|
proc setInput(data: openArray[byte]; len: int) {.inline.} =
|
||||||
if equals(data, buffer):
|
|
||||||
when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1):
|
|
||||||
x = move cached
|
|
||||||
else:
|
|
||||||
x = cached
|
|
||||||
else:
|
|
||||||
var pos = 1
|
|
||||||
#when (NimMajor, NimMinor, NimPatch) >= (1, 7, 1):
|
|
||||||
#x = move cached
|
|
||||||
fromData(data, pos, x)
|
|
||||||
|
|
||||||
proc setInput(x: var typ; data: openArray[byte]; len: int) {.inline.} =
|
|
||||||
setLen(buffer, len)
|
setLen(buffer, len)
|
||||||
var pos = 1
|
var pos = 1
|
||||||
toData(buffer, pos, x)
|
toData(buffer, pos, cached)
|
||||||
assert pos == len
|
assert pos == len
|
||||||
copyMem(unsafeAddr data, addr buffer[0], len)
|
copyMem(unsafeAddr data, addr buffer[0], len)
|
||||||
cached = move x
|
|
||||||
|
|
||||||
proc clearBuffer() {.inline.} =
|
proc clearBuffer() {.inline.} =
|
||||||
setLen(buffer, 1)
|
setLen(buffer, 1)
|
||||||
|
|
||||||
proc testOneInputImpl(data: openArray[byte]) =
|
proc testOneInputImpl(data: openArray[byte]) =
|
||||||
var x: typ
|
|
||||||
if data.len > 1: # Ignore '\n' passed by LibFuzzer.
|
if data.len > 1: # Ignore '\n' passed by LibFuzzer.
|
||||||
FuzzTarget(target)(getInput(x, data))
|
getInput(data)
|
||||||
|
FuzzTarget(target)(cached)
|
||||||
|
|
||||||
proc customMutatorImpl(data: openArray[byte]; maxLen: int; seed: int64): int {.nosan.} =
|
proc customMutatorImpl(data: openArray[byte]; maxLen: int; seed: int64): int {.nosan.} =
|
||||||
var r = initRand(seed)
|
var r = initRand(seed)
|
||||||
var x: typ
|
|
||||||
if data.len > 1:
|
if data.len > 1:
|
||||||
mgetInput(x, data)
|
getInput(data)
|
||||||
else:
|
else:
|
||||||
x = default(typeof(x))
|
cached = default(typeof(cached))
|
||||||
FuzzMutator(mutator)(x, maxLen-x.byteSize, r)
|
FuzzMutator(mutator)(cached, maxLen-cached.byteSize, r)
|
||||||
result = x.byteSize+1 # +1 for the skipped byte
|
result = cached.byteSize+1 # +1 for the skipped byte
|
||||||
if result <= maxLen:
|
if result <= maxLen:
|
||||||
setInput(x, data, result)
|
setInput(data, result)
|
||||||
else:
|
else:
|
||||||
clearBuffer()
|
clearBuffer()
|
||||||
result = data.len
|
result = data.len
|
||||||
|
|
Loading…
Reference in New Issue