This commit is contained in:
Antonis Geralis 2022-09-15 01:19:15 +03:00
parent 99b7a7cf54
commit 6168907b03
3 changed files with 11 additions and 7 deletions

View File

@ -155,8 +155,11 @@ proc toData(data: var openArray[byte]; pos: var int; input: T)
proc byteSize(x: T): int {.inline.} ## The size that will be consumed by the serialized type in bytes.
```
This is only necessary for objects that contain raw pointers. `mutate`, `default` and `==`
must also be defined. `drchaos/common` exports read/write procs that assist with this task.
This is only necessary for objects that contain raw pointers.
`drchaos/common` exports read/write procs that assist with this task.
`mutate`, `default` and `==` must also be defined.
Containers also need `mitems` or `mpairs` iterators.
### Dos and don'ts

View File

@ -619,10 +619,12 @@ template mutatorImpl*(target, mutator, typ: untyped) =
reset(cached)
setLen(buffer, 1)
proc testOneInputImpl(data: openArray[byte]) =
proc testOneInputImpl(data: openArray[byte]): cint =
if data.len > 1: # Ignore '\n' passed by LibFuzzer.
getInput(data)
FuzzTarget(target)(cached)
result = 0
else: result = -1
proc customMutatorImpl(data: openArray[byte]; maxLen: int; seed: int64): int {.nosan.} =
var r = initRand(seed)
@ -639,9 +641,8 @@ template mutatorImpl*(target, mutator, typ: untyped) =
result = data.len
proc LLVMFuzzerTestOneInput(data: ptr UncheckedArray[byte]; len: int): cint {.exportc.} =
result = 0
try:
testOneInputImpl(toOpenArray(data, 0, len-1))
result = testOneInputImpl(toOpenArray(data, 0, len-1))
finally:
# Call Nim's compiler api to report unhandled exceptions. See: Nim#18215
when compileOption("exceptions", "goto"):

View File

@ -44,7 +44,7 @@ proc deleteEdge*[T](x: var Graph[T]; `from`, to: Natural) =
if (let toNodeIdx = fromNode.edges.find(to.NodeIdx); toNodeIdx != -1):
template toNode: untyped = fromNode.edges[toNodeIdx]
fromNode.edges.delete(toNodeIdx)
#x.deleteNode(toNode.int) #sneaky bug?
x.deleteNode(toNode.int) # sneaky bug
when defined(runFuzzTests) and isMainModule:
import std/random, drchaos/[mutator, common]
@ -100,7 +100,7 @@ when defined(runFuzzTests) and isMainModule:
x.nodes[7].edges.len == 0:
doAssert false
# Here you could call library functions and check invariants.
# Such as when removing edges, the number of nodes remains the same.
# Such as when removing edges, the number of nodes should remain the same.
#var x = x
#let oldLen = x.nodes.len
#x.deleteEdge(1, 2)