aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-24 12:33:42 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-25 13:53:49 +0100
commit0e8f14dcc4db15a509dc2ba4b291e2c28fc51ca0 (patch)
tree87db770b7786c0018a58e979a2d2a8b8257d871b /prog/mutation.go
parent70393e5d05ae78166599755b835f0d465c815f48 (diff)
prog: refactor HeatMap
Provide NumMutations method instead of Size. It allows HeatMap to choose number of mutations better (e.g. for completely empty/flat images w/o interesting data).
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go8
1 files changed, 3 insertions, 5 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 881403247..96e11516c 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -401,11 +401,9 @@ func (r *randGen) mutateImage(image []byte) (data []byte, retry bool) {
if len(data) == 0 {
return image, true // Do not mutate empty data.
}
- hm := MakeGenericHeatmap(data)
- // At least two mutations, up to about one mutation every 128 KB of heatmap size.
- numMutations := r.Intn(hm.Size()/(1<<17)+1) + 2
- for i := 0; i < numMutations; i++ {
- index := hm.ChooseLocation(r.Rand)
+ hm := MakeGenericHeatmap(data, r.Rand)
+ for i := hm.NumMutations(); i > 0; i-- {
+ index := hm.ChooseLocation()
width := 1 << uint(r.Intn(4))
if index+width > len(data) {
width = 1