After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 142794 - gmarkup.c: advance_char
gmarkup.c: advance_char
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2004-05-19 19:15 UTC by Morten Welinder
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Morten Welinder 2004-05-19 19:15:48 UTC
See http://lists.gnome.org/archives/gtk-devel-list/2004-May/msg00085.html

--- gmarkup.c.~1.27.~	Wed Oct  8 21:45:24 2003
+++ gmarkup.c	Wed May 19 15:13:11 2004
@@ -662,16 +662,19 @@
 static gboolean
 advance_char (GMarkupParseContext *context)
 {
-
   context->iter = g_utf8_next_char (context->iter);
   context->char_number += 1;
+
+  if (context->iter == context->current_text_end)
+    return FALSE;
+
   if (*context->iter == '\n')
     {
       context->line_number += 1;
       context->char_number = 1;
     }
 
-  return context->iter != context->current_text_end;
+  return TRUE;
 }
 
 static gboolean
Comment 1 Matthias Clasen 2004-05-20 03:06:55 UTC
Hmm, it looks suspicious that the return value of advance_char is ignored in
many places, e.g.

        case STATE_AFTER_ATTRIBUTE_EQUALS_SIGN:
          /* Possible next state: INSIDE_ATTRIBUTE_VALUE_[SQ/DQ] */
          if (*context->iter == '"')
            {
              advance_char (context);
              context->state = STATE_INSIDE_ATTRIBUTE_VALUE_DQ;
              context->start = context->iter;
            }

If advance_char moves iter off the buffer, then context->start will be
invalid after this code...
Comment 2 Morten Welinder 2004-05-21 17:13:22 UTC
I checked all advance_char calls and they all end up checking whether we are
at the end of the buffer, most by getting to the "while" just outside the switch
you quote above.

So, I think the patch is good and complete, although you could add an initial

  g_return_val_if_fail (context->iter != context->current_text_end, FALSE)

to advance_char if you feel like it.