[gspell/wip/misc] InlineCheckerTextBuffer: make check_subregion() code more robust



commit 85dc920eab393d6b3e8177c9c500cfcd4c8a1ef1
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Aug 19 12:43:09 2017 +0200

    InlineCheckerTextBuffer: make check_subregion() code more robust
    
    Timm Bäder has sometimes this with valgrind:
    
     113 ==15797== Conditional jump or move depends on uninitialised value(s)
     114 ==15797==    at 0x5F1E766: g_utf8_find_next_char (gutf8.c:185)
     115 ==15797==    by 0x81855F7: check_subregion (gspell-inline-checker-text-buffer.c:345)
     116 ==15797==    by 0x8185C7B: check_visible_region_in_view (gspell-inline-checker-text-buffer.c:499)
     117 ==15797==    by 0x818601D: check_visible_region (gspell-inline-checker-text-buffer.c:567)
     118 ==15797==    by 0x818604A: timeout_cb (gspell-inline-checker-text-buffer.c:574)
     119 ==15797==    by 0x5F638F2: g_timeout_dispatch.lto_priv.218 (gmain.c:4633)
     120 ==15797==    by 0x5F619BB: g_main_dispatch (gmain.c:3148)
     121 ==15797==    by 0x5F6291C: g_main_context_dispatch (gmain.c:3813)
     122 ==15797==    by 0x5F62B0F: g_main_context_iterate (gmain.c:3886)
     123 ==15797==    by 0x5F62BE7: g_main_context_iteration (gmain.c:3947)
     124 ==15797==    by 0x55FC55A: g_application_run (gapplication.c:2401)
     125 ==15797==    by 0x108A99: _vala_main (main.vala:26)
     126 ==15797==    by 0x108AE2: main (main.vala:18)

 gspell/gspell-inline-checker-text-buffer.c |   31 ++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/gspell/gspell-inline-checker-text-buffer.c b/gspell/gspell-inline-checker-text-buffer.c
index 410678b..f458450 100644
--- a/gspell/gspell-inline-checker-text-buffer.c
+++ b/gspell/gspell-inline-checker-text-buffer.c
@@ -248,6 +248,12 @@ check_subregion (GspellInlineCheckerTextBuffer *spell,
 
        text = gtk_text_iter_get_slice (start, end);
 
+       if (text == NULL || text[0] == '\0')
+       {
+               g_free (text);
+               return;
+       }
+
        get_pango_log_attrs (text, &attrs, &n_attrs);
 
        attr_num = 0;
@@ -331,13 +337,10 @@ check_subregion (GspellInlineCheckerTextBuffer *spell,
                        word_start_char_pos = attr_num;
                }
 
-               if (cur_text_pos == NULL &&
-                   attr_num != n_attrs - 1)
+               if (attr_num == n_attrs - 1 ||
+                   cur_text_pos == NULL ||
+                   cur_text_pos[0] == '\0')
                {
-                       g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d.",
-                                  G_STRFUNC,
-                                  attr_num,
-                                  n_attrs - 1);
                        break;
                }
 
@@ -345,6 +348,22 @@ check_subregion (GspellInlineCheckerTextBuffer *spell,
                cur_text_pos = g_utf8_find_next_char (cur_text_pos, NULL);
        }
 
+       /* Sanity checks */
+
+       if (attr_num != n_attrs - 1)
+       {
+               g_warning ("%s(): problem in loop iteration, attr_num=%d but should be %d. "
+                          "End of string reached too early.",
+                          G_STRFUNC,
+                          attr_num,
+                          n_attrs - 1);
+       }
+
+       if (cur_text_pos != NULL && cur_text_pos[0] != '\0')
+       {
+               g_warning ("%s(): end of string not reached.", G_STRFUNC);
+       }
+
        g_free (text);
        g_free (attrs);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]