mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
terminal: addWithOverflow to detect max int
This commit is contained in:
@ -373,15 +373,16 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
|
||||
break :param null;
|
||||
}
|
||||
|
||||
// Ignore parameters that are too long
|
||||
if (self.param_acc_idx == std.math.maxInt(u8)) break :param null;
|
||||
|
||||
// A numeric value. Add it to our accumulator.
|
||||
if (self.param_acc_idx > 0) {
|
||||
self.param_acc *|= 10;
|
||||
}
|
||||
self.param_acc +|= c - '0';
|
||||
self.param_acc_idx += 1;
|
||||
|
||||
// Increment our accumulator index. If we overflow then
|
||||
// we're out of bounds and we exit immediately.
|
||||
self.param_acc_idx, const overflow = @addWithOverflow(self.param_acc_idx, 1);
|
||||
if (overflow > 0) break :param null;
|
||||
|
||||
// The client is expected to perform no action.
|
||||
break :param null;
|
||||
@ -910,3 +911,22 @@ test "csi followed by utf8" {
|
||||
try testing.expect(a[2] == null);
|
||||
}
|
||||
}
|
||||
|
||||
test "csi: too many params" {
|
||||
var p = init();
|
||||
_ = p.next(0x1B);
|
||||
_ = p.next('[');
|
||||
for (0..100) |_| {
|
||||
_ = p.next('1');
|
||||
_ = p.next(';');
|
||||
}
|
||||
_ = p.next('1');
|
||||
|
||||
{
|
||||
const a = p.next('C');
|
||||
try testing.expect(p.state == .ground);
|
||||
try testing.expect(a[0] == null);
|
||||
try testing.expect(a[1] == null);
|
||||
try testing.expect(a[2] == null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user