mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Bounds check "x >> y".
This commit is contained in:
1 parent
51da37c661
commit
5a0aea66a3
4 files changed
+29
No files matched your search
@@ -167,6 +167,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self) {
|
|||||||
v_bits |= 0;
|
v_bits |= 0;
|
||||||
v_n_bits += 8;
|
v_n_bits += 8;
|
||||||
}
|
}
|
||||||
|
v_bits >>= v_width;
|
||||||
goto label_0_break;
|
goto label_0_break;
|
||||||
v_n_bits = 0;
|
v_n_bits = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ var (
|
|||||||
one = big.NewInt(1)
|
one = big.NewInt(1)
|
||||||
ffff = big.NewInt(0xFFFF)
|
ffff = big.NewInt(0xFFFF)
|
||||||
|
|
||||||
|
maxIntBits = big.NewInt(t.MaxIntBits)
|
||||||
|
|
||||||
zeroExpr = a.NewExpr(a.FlagsTypeChecked, 0, t.IDZero, nil, nil, nil, nil)
|
zeroExpr = a.NewExpr(a.FlagsTypeChecked, 0, t.IDZero, nil, nil, nil, nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -511,8 +513,25 @@ func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u
|
|||||||
return zero, zero, nil
|
return zero, zero, nil
|
||||||
}
|
}
|
||||||
case t.KeyXBinarySlash:
|
case t.KeyXBinarySlash:
|
||||||
|
|
||||||
case t.KeyXBinaryShiftL:
|
case t.KeyXBinaryShiftL:
|
||||||
|
|
||||||
case t.KeyXBinaryShiftR:
|
case t.KeyXBinaryShiftR:
|
||||||
|
if lMin.Cmp(zero) < 0 {
|
||||||
|
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.String(q.idMap))
|
||||||
|
}
|
||||||
|
if rMin.Cmp(zero) < 0 {
|
||||||
|
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", rhs.String(q.idMap))
|
||||||
|
}
|
||||||
|
if rMin.Cmp(maxIntBits) >= 0 {
|
||||||
|
return zero, zero, nil
|
||||||
|
}
|
||||||
|
nMax := big.NewInt(0).Rsh(lMax, uint(rMin.Uint64()))
|
||||||
|
if rMax.Cmp(maxIntBits) >= 0 {
|
||||||
|
return zero, nMax, nil
|
||||||
|
}
|
||||||
|
return big.NewInt(0).Rsh(lMin, uint(rMax.Uint64())), nMax, nil
|
||||||
|
|
||||||
case t.KeyXBinaryAmp, t.KeyXBinaryPipe:
|
case t.KeyXBinaryAmp, t.KeyXBinaryPipe:
|
||||||
// TODO: should type-checking ensure that bitwise ops only apply to
|
// TODO: should type-checking ensure that bitwise ops only apply to
|
||||||
// *unsigned* integer types?
|
// *unsigned* integer types?
|
||||||
@@ -537,6 +556,7 @@ func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u
|
|||||||
// Return [0, z rounded up to the next power-of-2-minus-1]. This is
|
// Return [0, z rounded up to the next power-of-2-minus-1]. This is
|
||||||
// conservative, but works fine in practice.
|
// conservative, but works fine in practice.
|
||||||
return zero, bitMask(z.BitLen()), nil
|
return zero, bitMask(z.BitLen()), nil
|
||||||
|
|
||||||
case t.KeyXBinaryAmpHat:
|
case t.KeyXBinaryAmpHat:
|
||||||
case t.KeyXBinaryHat:
|
case t.KeyXBinaryHat:
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
package token
|
package token
|
||||||
|
|
||||||
|
// MaxIntBits is the largest size (in bits) of the i8, u8, i16, u16, etc.
|
||||||
|
// integer types.
|
||||||
|
const MaxIntBits = 64
|
||||||
|
|
||||||
// Flags are the low 16 bits of an ID. For example, they signify whether a
|
// Flags are the low 16 bits of an ID. For example, they signify whether a
|
||||||
// token is an operator, an identifier, etc.
|
// token is an operator, an identifier, etc.
|
||||||
//
|
//
|
||||||
@@ -471,6 +475,8 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
KeyTrue: {"true", IDTrue},
|
KeyTrue: {"true", IDTrue},
|
||||||
KeyZero: {"0", IDZero},
|
KeyZero: {"0", IDZero},
|
||||||
|
|
||||||
|
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
||||||
|
|
||||||
KeyI8: {"i8", IDI8},
|
KeyI8: {"i8", IDI8},
|
||||||
KeyI16: {"i16", IDI16},
|
KeyI16: {"i16", IDI16},
|
||||||
KeyI32: {"i32", IDI32},
|
KeyI32: {"i32", IDI32},
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ pub func lzw_decoder.decode?(dst ptr io.buf1, src ptr io.buf1, src_final bool)()
|
|||||||
bits |= 0 // TODO.
|
bits |= 0 // TODO.
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
|
// TODO: var code u32[..4095] = bits.low_bits(width)
|
||||||
|
bits >>= width
|
||||||
|
|
||||||
// TODO: implement.
|
// TODO: implement.
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in new issue
Block a user