提交 381c19e0 编写于 作者: A Adam Barth

If Color constructor is passed a value > 0xFFFFFFFF, Sky crashes

We now ensure the color is <= 0xFFFFFFFF.

Fixes #245

R=ianh@google.com

Review URL: https://codereview.chromium.org/1179413008.
上级 7c4662ce
......@@ -5,12 +5,12 @@
part of dart.sky;
class Color {
const Color(this._value);
const Color(int value) : _value = (value & 0xFFFFFFFF);
const Color.fromARGB(int a, int r, int g, int b) :
_value = (((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0));
_value = ((((a & 0xff) << 24) |
((r & 0xff) << 16) |
((g & 0xff) << 8) |
((b & 0xff) << 0)) & 0xFFFFFFFF);
final int _value;
int get value => _value;
......
CONSOLE: unittest-suite-wait-for-done
CONSOLE: PASS: paint set to black
CONSOLE: PASS: color created with out of bounds value
CONSOLE: PASS: color created with wildly out of bounds value
CONSOLE:
CONSOLE: All 3 tests passed.
CONSOLE: unittest-suite-success
DONE
import 'dart:sky' as sky;
import '../resources/third_party/unittest/unittest.dart';
import '../resources/unit.dart';
void main() {
initUnit();
test("paint set to black", () {
sky.Color c = new sky.Color(0x00000000);
sky.Paint p = new sky.Paint();
p.color = c;
expect(c.toString(), equals('Color(0x00000000)'));
});
test("color created with out of bounds value", () {
try {
sky.Color c = new sky.Color(0x100 << 24);
sky.Paint p = new sky.Paint();
p.color = c;
} catch (e) {
expect(e != null, equals(true));
}
});
test("color created with wildly out of bounds value", () {
try {
sky.Color c = new sky.Color(1 << 1000000);
sky.Paint p = new sky.Paint();
p.color = c;
} catch (e) {
expect(e != null, equals(true));
}
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册