Fix UB when reporting out-of-range values.
It's undefined behavior to cast a double to an int64 if the double is out of range. Our SkSL error tests managed to trigger UBSAN on the tree, pinpointing the issue (which we had already written up a bug for). Change-Id: Ia06896732223ff310f2c175efcbeb96ba5786fa8 Bug: skia:12863 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/505678 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
e7985f22fa
commit
ada59c148e
@ -954,9 +954,11 @@ bool Type::checkForOutOfRangeLiteral(const Context& context, double value, int l
|
||||
if (this->isInteger()) {
|
||||
if (value < this->minimumValue() || value > this->maximumValue()) {
|
||||
// We found a value that can't fit in the type. Flag it as an error.
|
||||
context.fErrors->error(line, "integer is out of range for type '" +
|
||||
this->displayName() + "': " +
|
||||
std::to_string((SKSL_INT)value));
|
||||
context.fErrors->error(
|
||||
line,
|
||||
SkSL::String::printf("integer is out of range for type '%s': %.0f",
|
||||
this->displayName().c_str(),
|
||||
std::floor(value)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ error: 7: expected 'int', but found 'bool'
|
||||
error: 8: expected 'int', but found 'int2'
|
||||
error: 9: missing index in '[]'
|
||||
error: 10: integer is out of range for type 'int': 4000000000
|
||||
error: 11: integer is out of range for type 'int': -9223372036854775808
|
||||
error: 11: integer is out of range for type 'int': 100000002004087734272
|
||||
error: 13: array size must be positive
|
||||
error: 14: array size must be positive
|
||||
error: 15: array size must be positive
|
||||
@ -22,5 +22,5 @@ error: 19: array size must be an integer
|
||||
error: 20: array size must be an integer
|
||||
error: 21: expected array dimension
|
||||
error: 22: integer is out of range for type 'int': 4000000000
|
||||
error: 23: integer is out of range for type 'int': -9223372036854775808
|
||||
error: 23: integer is out of range for type 'int': 100000002004087734272
|
||||
23 errors
|
||||
|
Loading…
Reference in New Issue
Block a user