aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prog/generation.go2
-rw-r--r--prog/mutation.go2
-rw-r--r--prog/rand.go7
3 files changed, 6 insertions, 5 deletions
diff --git a/prog/generation.go b/prog/generation.go
index dcb8dc2ac..85d1bbb02 100644
--- a/prog/generation.go
+++ b/prog/generation.go
@@ -16,7 +16,7 @@ func (target *Target) Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Pro
r := newRand(target, rs)
s := newState(target, ct, nil)
for len(p.Calls) < ncalls {
- calls := r.generateCall(s, p)
+ calls := r.generateCall(s, p, len(p.Calls))
for _, c := range calls {
s.analyze(c)
p.Calls = append(p.Calls, c)
diff --git a/prog/mutation.go b/prog/mutation.go
index b0702ebba..f19813148 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -134,7 +134,7 @@ func (ctx *mutator) insertCall() bool {
c = p.Calls[idx]
}
s := analyze(ctx.ct, ctx.corpus, p, c)
- calls := r.generateCall(s, p)
+ calls := r.generateCall(s, p, idx)
// TODO: the program might have more than ncalls
p.insertBefore(c, calls)
return true
diff --git a/prog/rand.go b/prog/rand.go
index 3306ced66..f8c640161 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -490,14 +490,15 @@ func (r *randGen) nOutOf(n, outOf int) bool {
return v < n
}
-func (r *randGen) generateCall(s *state, p *Prog) []*Call {
+func (r *randGen) generateCall(s *state, p *Prog, insertionPoint int) []*Call {
idx := 0
- if s.ct == nil {
+ if s.ct == nil || insertionPoint <= 0 {
idx = r.Intn(len(r.target.Syscalls))
} else {
call := -1
if len(p.Calls) != 0 {
- call = p.Calls[r.Intn(len(p.Calls))].Meta.ID
+ // Choosing the base call is based on the insertion point of the new calls sequence.
+ call = p.Calls[r.Intn(insertionPoint)].Meta.ID
}
idx = s.ct.Choose(r.Rand, call)
}