Code

Fix segfault when starting tig in pager mode
authorJonas Fonseca <fonseca@diku.dk>
Sat, 26 Jun 2010 00:01:07 +0000 (20:01 -0400)
committerJonas Fonseca <fonseca@diku.dk>
Sat, 26 Jun 2010 00:01:51 +0000 (20:01 -0400)
Thanks to Pierre Habouzit and Tobias Heinlein for reporting this.

NEWS
tig.c

diff --git a/NEWS b/NEWS
index 41729f7f13dd4fd4f503ae969d3b0d0915f20315..1a0960aa44a9f67370455c0d44048a4806370292 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Bug fixes:
 
  - Fix problem with empty diff views when file specs were passed on the
    command line.
+ - Fix segfault when starting tig in pager mode.
 
 tig-0.16
 --------
diff --git a/tig.c b/tig.c
index 5f4c2635c3a719c5ea06d01bc08be62b042802a5..ae335183f472645e08687af539be91ec2213fb36 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -2316,7 +2316,7 @@ static struct view views[] = {
        VIEW_(BLAME,  "blame",  &blame_ops,  TRUE,  ref_commit),
        VIEW_(BRANCH, "branch", &branch_ops, TRUE,  ref_head),
        VIEW_(HELP,   "help",   &help_ops,   FALSE, ""),
-       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, "stdin"),
+       VIEW_(PAGER,  "pager",  &pager_ops,  FALSE, ""),
        VIEW_(STATUS, "status", &status_ops, TRUE,  ""),
        VIEW_(STAGE,  "stage",  &stage_ops,  TRUE,  ""),
 };
@@ -3708,6 +3708,13 @@ view_driver(struct view *view, enum request request)
                break;
 
        case REQ_VIEW_PAGER:
+               if (view == NULL) {
+                       if (!io_open(&VIEW(REQ_VIEW_PAGER)->io, ""))
+                               die("Failed to open stdin");
+                       open_view(view, request, OPEN_PREPARED);
+                       break;
+               }
+
                if (!VIEW(REQ_VIEW_PAGER)->pipe && !VIEW(REQ_VIEW_PAGER)->lines) {
                        report("No pager content, press %s to run command from prompt",
                               get_key(view->keymap, REQ_PROMPT));
@@ -7764,10 +7771,8 @@ parse_options(int argc, const char *argv[])
        const char **filter_argv = NULL;
        int i;
 
-       if (!isatty(STDIN_FILENO)) {
-               io_open(&VIEW(REQ_VIEW_PAGER)->io, "");
+       if (!isatty(STDIN_FILENO))
                return REQ_VIEW_PAGER;
-       }
 
        if (argc <= 1)
                return REQ_VIEW_MAIN;