From 4a70670dadb097960c2f70e2bad0459a93badd39 Mon Sep 17 00:00:00 2001 From: kkHAIKE Date: Mon, 19 Sep 2022 18:42:51 +0800 Subject: [PATCH] fix some little bug --- README.md | 2 +- contextcheck.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 368e97f..a383228 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ func call3() { ``` ### force mark specify function have server-side http.Request parameter -default behavior is mark http.HandlerFunc only. +default behavior is mark http.HandlerFunc or a function use r.Context(). ```go // @contextcheck(req_has_ctx) diff --git a/contextcheck.go b/contextcheck.go index 63a5d30..bea2e65 100644 --- a/contextcheck.go +++ b/contextcheck.go @@ -584,6 +584,7 @@ func (r *runner) checkFuncWithCtx(f *ssa.Function, tp entryType) { func (r *runner) checkFuncWithoutCtx(f *ssa.Function, checkingMap map[string]bool) (ret bool) { ret = true orgKey := f.RelString(nil) + var seted bool for _, b := range f.Blocks { for _, instr := range b.Instrs { tp, ok := r.getCtxType(instr) @@ -614,7 +615,10 @@ func (r *runner) checkFuncWithoutCtx(f *ssa.Function, checkingMap map[string]boo ret = false // save the call link - r.setFact(orgKey, res.Valid, res.Funcs...) + if !seted { + seted = true + r.setFact(orgKey, res.Valid, res.Funcs...) + } } continue } @@ -638,7 +642,8 @@ func (r *runner) checkFuncWithoutCtx(f *ssa.Function, checkingMap map[string]boo valid := r.checkFuncWithoutCtx(ff, checkingMap) r.setFact(key, valid, ff.Name()) - if res, ok := r.getValue(key, ff); ok { + if res, ok := r.getValue(key, ff); ok && !valid && !seted { + seted = true r.setFact(orgKey, valid, res.Funcs...) } if !valid {