aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorEmanuel Rylke <ema-fox@web.de>2014-12-06 20:59:04 +0100
committerEmanuel Rylke <ema-fox@web.de>2014-12-06 20:59:04 +0100
commitb5e7cba598302d3d35ba8a3b735501b1be23b67f (patch)
tree9c1f8d0594a59779a1ea65cb287ea2822aa89464 /components/script/textinput.rs
parentf99c0e2c1538d3c6e4d857a2062e408905922207 (diff)
downloadservo-b5e7cba598302d3d35ba8a3b735501b1be23b67f.tar.gz
servo-b5e7cba598302d3d35ba8a3b735501b1be23b67f.zip
Fix bug of TextInput.adjust_horizontal causing stack overflow or wraparound
When the edit_point is in the first position of a multiline TextInput adjust_horizontal(-1) moves the edit_point to the end of the first line. When the first line is empty this causes a stack overflow. When the edit_point is in the last position adjust_horizontal(1) causes a stack overflow.
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs29
1 files changed, 10 insertions, 19 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index c925c0a5d82..d94ae6c4ee6 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -178,29 +178,20 @@ impl TextInput {
/// adjusted vertically and the process repeats with the remaining adjustment requested.
fn adjust_horizontal(&mut self, adjust: int) {
if adjust < 0 {
- if self.multiline {
- let remaining = self.edit_point.index;
- if adjust.abs() as uint > remaining {
- self.edit_point.index = 0;
- self.adjust_vertical(-1);
- self.edit_point.index = self.current_line_length();
- self.adjust_horizontal(adjust + remaining as int);
- } else {
- self.edit_point.index = (self.edit_point.index as int + adjust) as uint;
- }
+ let remaining = self.edit_point.index;
+ if adjust.abs() as uint > remaining && self.edit_point.line > 0 {
+ self.adjust_vertical(-1);
+ self.edit_point.index = self.current_line_length();
+ self.adjust_horizontal(adjust + remaining as int);
} else {
self.edit_point.index = max(0, self.edit_point.index as int + adjust) as uint;
}
} else {
- if self.multiline {
- let remaining = self.current_line_length() - self.edit_point.index;
- if adjust as uint > remaining {
- self.edit_point.index = 0;
- self.adjust_vertical(1);
- self.adjust_horizontal(adjust - remaining as int);
- } else {
- self.edit_point.index += adjust as uint;
- }
+ let remaining = self.current_line_length() - self.edit_point.index;
+ if adjust as uint > remaining && self.edit_point.line < self.lines.len() - 1 {
+ self.edit_point.index = 0;
+ self.adjust_vertical(1);
+ self.adjust_horizontal(adjust - remaining as int);
} else {
self.edit_point.index = min(self.current_line_length(),
self.edit_point.index + adjust as uint);