fix(tty): 修复tty对tab进行处理时产生数组越界panic的问题 (#1015)

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin 2024-10-26 12:55:31 +08:00 committed by GitHub
parent a9e28e9ce9
commit 4dd4856f93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 13 deletions

View File

@ -1284,13 +1284,11 @@ impl VirtualConsoleData {
// 水平制表符Horizontal Tab // 水平制表符Horizontal Tab
self.pos -= self.state.x; self.pos -= self.state.x;
let ret = self.tab_stop.next_index(self.state.x + 1); self.state.x = self
.tab_stop
if let Some(x) = ret { .next_index(self.state.x + 1)
self.state.x = x; .unwrap_or(self.cols - 1);
} else { self.state.x = core::cmp::min(self.state.x, self.cols - 1);
self.state.x = self.cols - 1;
}
self.pos += self.state.x; self.pos += self.state.x;
// TODO: notify // TODO: notify
@ -1552,7 +1550,7 @@ impl VirtualConsoleData {
} }
// 未找到 // 未找到
if (!self.utf || self.display_ctrl || c < 128) && c & !charmask == 0 { if (!self.utf || self.display_ctrl || c < 128) && (c & !charmask) == 0 {
tc = c; tc = c;
} else { } else {
let tmp = self.unicode_to_index(0xfffd); let tmp = self.unicode_to_index(0xfffd);
@ -1587,7 +1585,7 @@ impl VirtualConsoleData {
// TODO: 处理unicode screen buf // TODO: 处理unicode screen buf
if himask != 0 { if himask != 0 {
tc = (if tc & 0x100 != 0 { himask as u32 } else { 0 }) | (tc & 0xff); tc = (if (tc & 0x100) != 0 { himask as u32 } else { 0 }) | (tc & 0xff);
} }
tc |= ((attr as u32) << 8) & (!himask as u32); tc |= ((attr as u32) << 8) & (!himask as u32);
@ -1602,7 +1600,7 @@ impl VirtualConsoleData {
// ); // );
self.screen_buf[self.pos] = tc as u16; self.screen_buf[self.pos] = tc as u16;
if draw.x.is_none() { if self.should_update() && draw.x.is_none() {
// 设置draw参数 // 设置draw参数
draw.x = Some(self.state.x as u32); draw.x = Some(self.state.x as u32);
draw.offset = self.pos; draw.offset = self.pos;
@ -1619,7 +1617,7 @@ impl VirtualConsoleData {
} }
width -= 1; width -= 1;
if width == 0 { if width <= 0 {
break; break;
} }
let tmp = self.unicode_to_index(' ' as u32); let tmp = self.unicode_to_index(' ' as u32);
@ -1629,7 +1627,6 @@ impl VirtualConsoleData {
if invert { if invert {
self.flush(draw); self.flush(draw);
} }
true true
} }

View File

@ -40,7 +40,7 @@ impl FontDesc {
} }
for (first, last) in Self::DOUBLE_WIDTH_RANGE { for (first, last) in Self::DOUBLE_WIDTH_RANGE {
if ch > *first && ch < *last { if ch >= *first && ch < *last {
return true; return true;
} }
} }