This commit is contained in:
Antonis Geralis 2022-09-04 21:53:13 +03:00
parent 9e50082946
commit 9181760888
3 changed files with 6 additions and 6 deletions

View File

@ -142,7 +142,7 @@ 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 destructor-based types.
This is only necessary for destructor-based types. `mutate`, `default` and `==` must also be defined.
`drchaos/common` exports read/write procs that assist with this task.
### What's not supported

View File

@ -76,10 +76,10 @@ type
EncodingDefect = object of Defect
DecodingDefect = object of Defect
proc raiseEncoding() {.noinline, noreturn.} =
proc raiseEncoding*() {.noinline, noreturn.} =
raise newException(EncodingDefect, "Can't write bytes to buffer.")
proc raiseDecoding() {.noinline, noreturn.} =
proc raiseDecoding*() {.noinline, noreturn.} =
raise newException(DecodingDefect, "Can't read bytes from buffer.")
proc equals*(a, b: openArray[byte]): bool =

View File

@ -11,7 +11,7 @@ when (NimMajor, NimMinor, NimPatch) < (1, 7, 1):
result = cast[T](r.next shr (sizeof(uint64) - sizeof(T))*8)
when not defined(fuzzerStandalone):
proc mutate(data: ptr UncheckedArray[byte], len, maxLen: int): int {.
proc mutate*(data: ptr UncheckedArray[byte], len, maxLen: int): int {.
importc: "LLVMFuzzerMutate".}
template `+!`(p: pointer, s: int): untyped =
@ -173,7 +173,7 @@ proc mutateArray*[S, T](value: array[S, T]; r: var Rand): array[S, T] {.inline.}
template repeatMutate*(call: untyped) =
if not enforceChanges and rand(r, RandomToDefaultRatio - 1) == 0:
discard
reset(value)
else:
var tmp = value
for i in 1..10:
@ -182,7 +182,7 @@ template repeatMutate*(call: untyped) =
template repeatMutateInplace*(call: untyped) =
if not enforceChanges and rand(r, RandomToDefaultRatio - 1) == 0:
discard
reset(value)
else:
var tmp {.inject.} = value
for i in 1..10: