mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-26 17:01:35 +01:00
Stop bounds checking after a jump or return.
This commit is contained in:
1 parent
5cce3afe4c
commit
f6cc7950ff
2 files changed
+16
-12
No files matched your search
+15
-9
@@ -145,6 +145,18 @@ func bcheckField(idMap *t.IDMap, n *a.Field) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) bcheckBlock(block []*a.Node) error {
|
||||
for _, o := range block {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
return err
|
||||
}
|
||||
if k := o.Kind(); k == a.KJump || k == a.KReturn {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
q.errFilename, q.errLine = n.Raw().FilenameLine()
|
||||
|
||||
@@ -385,11 +397,9 @@ func (q *checker) bcheckIf(n *a.If) error {
|
||||
|
||||
// Check the if-true branch, assuming the if condition.
|
||||
q.facts.appendFact(n.Condition())
|
||||
for _, o := range n.BodyIfTrue() {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
if err := q.bcheckBlock(n.BodyIfTrue()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !terminates(n.BodyIfTrue()) {
|
||||
branches = append(branches, snapshot(q.facts))
|
||||
}
|
||||
@@ -402,11 +412,9 @@ func (q *checker) bcheckIf(n *a.If) error {
|
||||
q.facts.appendFact(inverse)
|
||||
}
|
||||
if bif := n.BodyIfFalse(); len(bif) > 0 {
|
||||
for _, o := range bif {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
if err := q.bcheckBlock(bif); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if !terminates(bif) {
|
||||
branches = append(branches, snapshot(q.facts))
|
||||
}
|
||||
@@ -494,11 +502,9 @@ func (q *checker) bcheckWhile(n *a.While) error {
|
||||
q.facts.appendFact(n.Condition())
|
||||
}
|
||||
// Check the body.
|
||||
for _, o := range n.Body() {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Check the pre and inv conditions on the implicit continue after the
|
||||
// body.
|
||||
if !terminates(n.Body()) {
|
||||
|
||||
+1
-3
@@ -333,8 +333,7 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
|
||||
// Run bounds checks.
|
||||
if c.flags&FlagsOnlyTypeCheck == 0 {
|
||||
for _, o := range n.Body() {
|
||||
if err := q.bcheckStatement(o); err != nil {
|
||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||
return &Error{
|
||||
Err: err,
|
||||
Filename: q.errFilename,
|
||||
@@ -344,7 +343,6 @@ func (c *Checker) checkFuncBody(node *a.Node) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n.Node().SetTypeChecked()
|
||||
if err := n.Node().Walk(func(o *a.Node) error {
|
||||
|
||||
Reference in new issue
Block a user