From ce17422142df2dadd22a2b3e40d7de43e5a1c12c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 12 Jun 2017 12:06:00 -0400
Subject: [PATCH 17/44] FIXME: use idx rather than ptrs

---
 gcc/spellcheck-enchant.c | 50 +++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/gcc/spellcheck-enchant.c b/gcc/spellcheck-enchant.c
index 48f2ece..c6f1e37 100644
--- a/gcc/spellcheck-enchant.c
+++ b/gcc/spellcheck-enchant.c
@@ -358,11 +358,10 @@ spellcheck_enchant_check_comment (cpp_reader *, source_location loc,
       gcc_assert (content[len - 2] == '*');
       gcc_assert (content[len - 1] == '/');
     }
-  const unsigned char *iter = content + 2;
-  const unsigned char *after_last_char = content + len;
   if (c_style)
-    after_last_char -= 2;
-  const unsigned char *word_start = NULL;
+    len -= 2;
+
+  int word_start_idx = -1;
 
   const struct line_map *map = linemap_lookup (line_table, loc);
   const line_map_ordinary *ord_map = linemap_check_ordinary (map);
@@ -373,15 +372,16 @@ spellcheck_enchant_check_comment (cpp_reader *, source_location loc,
   int word_start_line = line;
 
   bool ignore_until_next_whitespace = true;
-  while (iter < after_last_char)
+  size_t idx;
+  for (idx = 2; idx < len; idx++)
     {
-      unsigned char ch = *iter;
+      unsigned char ch = content[idx];
       if (ISALPHA (ch) || ch == '_' || ch == '\'')
 	{
-	  if (!word_start)
+	  if (word_start_idx == -1)
 	    {
 	      /* We have the start of a word.  */
-	      word_start = iter;
+	      word_start_idx = idx;
 	      word_start_column = column;
 	      word_start_line = line;
 	    }
@@ -391,51 +391,54 @@ spellcheck_enchant_check_comment (cpp_reader *, source_location loc,
 	  /* If we see a '.' or '/' followed by non-whitespace, treat it as
 	     a filename, and ignore it.  */
 	  if (ch == '.' || ch == '/')
-	    if (iter + 1 < after_last_char)
-	      if (!ISSPACE (*(iter + 1)))
+	    if (idx + 1 < len)
+	      if (!ISSPACE (content[idx + 1]))
 		ignore_until_next_whitespace = true;
 
 	  /* If we see a '@' followed by non-whitespace, treat it as
 	     an email address, and ignore it.  */
 	  if (ch == '@')
-	    if (iter + 1 < after_last_char)
-	      if (!ISSPACE (*(iter + 1)))
+	    if (idx + 1 < len)
+	      if (!ISSPACE (content[idx + 1]))
 		ignore_until_next_whitespace = true;
 
 	  /* If we see a '-' after whitespace, treat it as a command-line
 	     option, and ignore it.  */
 	  if (ch == '-')
-	    if (iter > content)
-	      if (ISSPACE (*(iter - 1)))
+	    if (idx > 0)
+	      if (ISSPACE (content[idx - 1]))
 		ignore_until_next_whitespace = true;
 
-	  if (word_start)
+	  if (word_start_idx != -1)
 	    {
 	      /* We have a word ending.  */
-	      size_t word_len = iter - word_start;
+	      size_t word_len = idx - word_start_idx;
 	      /* Don't check any comments that appear to contain DejaGnu
 		 directives.  */
 	      if (word_len >= 2)
-		if (0 == strncmp ((const char *)word_start, "dg", 2))
+		if (0 == strncmp ((const char *)(content + word_start_idx),
+				  "dg", 2))
 		  return;
 
 	      /* Detect things that look like URLs.  */
 	      /* "www."  */
 	      if (word_len == 3 && ch == '.')
-		if (0 == strncmp ((const char *)word_start, "www", 3))
+		if (0 == strncmp ((const char *)(content + word_start_idx),
+				  "www", 3))
 		  ignore_until_next_whitespace = true;
 
 	      /* "http:"  */
 	      if (word_len == 4 && ch == ':')
-		if (0 == strncmp ((const char *)word_start, "http", 4))
+		if (0 == strncmp ((const char *)(content + word_start_idx),
+				  "http", 4))
 		  ignore_until_next_whitespace = true;
 	      // FIXME: https
 	      // FIXME: helper function
 
 	      if (!ignore_until_next_whitespace)
-		spellcheck_word (word_start, word_len, ord_map,
+		spellcheck_word (content + word_start_idx, word_len, ord_map,
 				 word_start_line, word_start_column);
-	      word_start = NULL;
+	      word_start_idx = -1;
 	    }
 	}
       if (ISSPACE (ch))
@@ -447,11 +450,10 @@ spellcheck_enchant_check_comment (cpp_reader *, source_location loc,
 	}
       else
 	column++;
-      iter++;
     }
-  if (word_start)
+  if (word_start_idx != -1)
     if (!ignore_until_next_whitespace)
-      spellcheck_word (word_start, iter - word_start, ord_map,
+      spellcheck_word (content + word_start_idx, idx - word_start_idx, ord_map,
 		       word_start_line, word_start_column);
 }
 
-- 
1.8.5.3

