diff --git a/pango/opentype/hb-ot-layout-gsubgpos-private.hh b/pango/opentype/hb-ot-layout-gsubgpos-private.hh
index b21939a..2a8980d 100644
--- a/pango/opentype/hb-ot-layout-gsubgpos-private.hh
+++ b/pango/opentype/hb-ot-layout-gsubgpos-private.hh
@@ -120,16 +120,16 @@ static inline bool match_input (APPLY_ARG_DEF,
   if (HB_UNLIKELY (buffer->in_pos + count > end))
     return false;
 
-  for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++)
+  for (i = 0, j = buffer->in_pos + 1; i < count; i++, j++)
   {
     while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, NULL))
     {
-      if (HB_UNLIKELY (j + count - i == end))
+      if (HB_UNLIKELY (j + count - i - 1 == end))
 	return false;
       j++;
     }
 
-    if (HB_LIKELY (!match_func (IN_GLYPH (j), input[i - 1], match_data)))
+    if (HB_LIKELY (!match_func (IN_GLYPH (j), input[i], match_data)))
       return false;
   }
 
