commit a22b9074497ed9cca2fc7ab2c3a917027346cd97
Author: Andreas Henriksson <andreas@fatal.se>
Date:   Sun Apr 6 17:40:38 2014 +0200

    validate returned iterator before passing to get_buffer
    
    This avoids crashing in get_buffer when get_iter returns empty iter.
    Unfortunately get_iter doesn't return any indications if it
    succeded (and filled the passed reference with useful information)
    or failed (and didn't touch the references iter).
    An improvement of the gtksourceview API might be useful here.
    For now, work around this by knowing that vala will create an
    empty iter used as reference to get_iter and then compare it
    against another empty iter to know if get_iter succeded or failed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727250
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=742840

diff --git a/src/math-display.vala b/src/math-display.vala
index f4da9b3..e5b347c 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -450,7 +450,18 @@ public class FunctionCompletionProvider : CompletionProvider
 
     public override void populate (Gtk.SourceCompletionContext context)
     {
-        Gtk.TextBuffer text_buffer = context.get_iter ().get_buffer ();
+        Gtk.TextIter emptyiter = {};
+
+        var iter1 = context.get_iter ();
+        // This check is based on the assumption/knowledge
+        // that vala nulls the iter before passing at as a reference.
+        // The gtksourceview api has no way to signal error.
+        if (iter1 == emptyiter)
+        {
+            return;
+        }
+
+        Gtk.TextBuffer text_buffer = iter1.get_buffer ();
         MathFunction[] functions = get_matches_for_completion_at_cursor (text_buffer);
 
         List<Gtk.SourceCompletionItem>? proposals = null;
@@ -501,7 +512,18 @@ public class VariableCompletionProvider : CompletionProvider
 
     public override void populate (Gtk.SourceCompletionContext context)
     {
-        Gtk.TextBuffer text_buffer = context.get_iter ().get_buffer ();
+        Gtk.TextIter emptyiter = {};
+
+        var iter1 = context.get_iter ();
+        // This check is based on the assumption/knowledge
+        // that vala nulls the iter before passing at as a reference.
+        // The gtksourceview api has no way to signal error.
+        if (iter1 == emptyiter)
+        {
+            return;
+        }
+
+        Gtk.TextBuffer text_buffer = iter1.get_buffer ();
         string[] variables = get_matches_for_completion_at_cursor (text_buffer, _equation.variables);
 
         List<Gtk.SourceCompletionItem>? proposals = null;
