mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 08:47:56 +01:00
Reject "x as T" if x can overflow T.
This commit is contained in:
1 parent
587bc2a55d
commit
8cd43d2c3c
2 files changed
+7
-7
No files matched your search
@@ -576,13 +576,12 @@ func (q *checker) bcheckExpr(n *a.Expr, depth uint32) (*big.Int, *big.Int, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
nMin, nMax := max(lMin, rMin), min(lMax, rMax)
|
if lMin.Cmp(rMin) < 0 || lMax.Cmp(rMax) > 0 {
|
||||||
// TODO: check if nMin > nMax.
|
return nil, nil, fmt.Errorf("check: expression %q bounds [%v..%v] is not within bounds [%v..%v]",
|
||||||
//
|
n.LHS().Expr().String(q.tm), lMin, lMax, rMin, rMax,
|
||||||
// TODO: should it be a compile time error if "x as T" can narrow
|
)
|
||||||
// the range? Do we want a separate "~as" operator that ignores
|
}
|
||||||
// overflow?
|
return lMin, lMax, nil
|
||||||
return nMin, nMax, nil
|
|
||||||
}
|
}
|
||||||
return q.bcheckExprBinaryOp(n.LHS().Expr(), n.ID0().Key(), n.RHS().Expr(), depth)
|
return q.bcheckExprBinaryOp(n.LHS().Expr(), n.ID0().Key(), n.RHS().Expr(), depth)
|
||||||
case t.FlagsAssociativeOp:
|
case t.FlagsAssociativeOp:
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
|||||||
n_bits -= width
|
n_bits -= width
|
||||||
|
|
||||||
if code < clear_code {
|
if code < clear_code {
|
||||||
|
assert code < 256 via "a < b: a < c; c <= b"(c:clear_code)
|
||||||
in.dst.write_u8?(x:code as u8)
|
in.dst.write_u8?(x:code as u8)
|
||||||
if use_save_code {
|
if use_save_code {
|
||||||
this.suffixes[save_code] = code as u8
|
this.suffixes[save_code] = code as u8
|
||||||
|
|||||||
Reference in new issue
Block a user