OSDN Git Service

(index0): New function.
authorkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Aug 1994 23:31:15 +0000 (23:31 +0000)
committerkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 15 Aug 1994 23:31:15 +0000 (23:31 +0000)
(trigraph_pcp): Use index0 instead of index, so that a null byte
doesn't suppress further trigraph preprocessing.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@7934 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cccp.c

index 3ba2bfb..aa564fd 100644 (file)
@@ -2195,6 +2195,33 @@ path_include (path)
     }
 }
 \f
+/* Return the address of the first character in S that equals C.
+   S is an array of length N, possibly containing '\0's, and followed by '\0'.
+   Return 0 if there is no such character.  Assume that C itself is not '\0'.
+   If we knew we could use memchr, we could just invoke memchr (S, C, N),
+   but unfortunately memchr isn't autoconfigured yet.  */
+
+static U_CHAR *
+index0 (s, c, n)
+     U_CHAR *s;
+     int c;
+     int n;
+{
+  for (;;) {
+    char *q = index (s, c);
+    if (q)
+      return (U_CHAR *) q;
+    else {
+      int l = strlen (s);
+      if (l == n)
+       return 0;
+      l++;
+      s += l;
+      n -= l;
+    }
+  }
+}
+\f
 /* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
    before main CCCP processing.  Name `pcp' is also in honor of the
    drugs the trigraph designers must have been on.
@@ -2208,11 +2235,12 @@ static void
 trigraph_pcp (buf)
      FILE_BUF *buf;
 {
-  register U_CHAR c, *fptr, *bptr, *sptr;
+  register U_CHAR c, *fptr, *bptr, *sptr, *lptr;
   int len;
 
   fptr = bptr = sptr = buf->buf;
-  while ((sptr = (U_CHAR *) index (sptr, '?')) != NULL) {
+  lptr = fptr + buf->length;
+  while ((sptr = (U_CHAR *) index0 (sptr, '?', lptr - sptr)) != NULL) {
     if (*++sptr != '?')
       continue;
     switch (*++sptr) {