Skip to content

Commit

Permalink
Fix runtime panic with colpan or rowspan set to zero
Browse files Browse the repository at this point in the history
Make it a compiler error instead:
Fix panic:
```
panicked at internal/core/layout.rs:459:33:
index out of bounds: the len is 2 but the index is 2
```

ChangeLog: Transformed runtime panic with `colspan:0` or `rowspan:0` into a compile error
  • Loading branch information
ogoffart committed Jan 15, 2025
1 parent 22ad614 commit 6869865
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/compiler/passes/lower_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ fn eval_const_expr(
) -> Option<u16> {
match expression {
Expression::NumberLiteral(v, Unit::None) => {
if *v < 0. || *v > u16::MAX as f64 || !v.trunc().approx_eq(v) {
if *v < 1. || *v > u16::MAX as f64 || !v.trunc().approx_eq(v) {
diag.push_error(format!("'{}' must be a positive integer", name), span);
None
} else {
Expand Down
8 changes: 8 additions & 0 deletions internal/compiler/tests/syntax/basic/layout2.slint
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export X := Rectangle {
Rectangle { row: 3; }
// ^error{row used outside of a GridLayout}
}

Rectangle {
// This would cause panic at runtime
rowspan: 0;
// ^error{'rowspan' must be a positive integer}
colspan: 0;
// ^error{'colspan' must be a positive integer}
}
}

Text { colspan: 3; }
Expand Down

0 comments on commit 6869865

Please sign in to comment.