Code

move_view: fix view->offset overflow bug
authorJonas Fonseca <fonseca@diku.dk>
Tue, 29 May 2007 11:08:21 +0000 (13:08 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Tue, 29 May 2007 11:08:21 +0000 (13:08 +0200)
Reproducable by opening the tree view, then maximizing the blob view,
move up, and then closing the blob view, causing the view->offset to
have "wrapped around" and nothing to be displayed in the tree view.

The invalid update of view->offset only happend when moving
non-displayed views.  Instead use the checked scroll_steps variable
instead of the steps variable.  Add a guarding assert after the update.

tig.c

diff --git a/tig.c b/tig.c
index 00888dd7a504160cb88ea758ea19315e57bb752b..7cf25ca4507a26d7c493278e15e2bfc2f71e126f 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -1622,7 +1622,8 @@ move_view(struct view *view, enum request request)
        }
 
        if (!view_is_displayed(view)) {
-               view->offset += steps;
+               view->offset += scroll_steps;
+               assert(0 <= view->offset && view->offset < view->lines);
                view->ops->select(view, &view->line[view->lineno]);
                return;
        }