Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1232379

Logic error in methods named regionMatches in class String

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      solaris_1
    • Verification:
      Not verified

      Description

      Consider the two methods named regionMatches in class String.
      Because of a programming error,, if the len argument is the most
      negative integer, the while loop will not terminate immediately
      (integer overflow occurs) and there may actually bean attempt to
      index off the end of one of the arrays.

      To correct this error, the test (--len >= 0) should be (len-- > 0).
      Better yet, write "for(; len > 0; --len)".


          public boolean regionMatches(boolean ignoreCase,
      int toffset,
      String other, int ooffset, int len) {
      char ta[] = value;
      int to = offset + toffset;
      int tlim = offset + count;
      char pa[] = other.value;
      char trt[] = Character.upCase;
      int po = other.offset + ooffset;
      int plim = po + other.count;
      if ((ooffset < 0) || (toffset < 0) || (to + len > tlim) || (po + len > plim)) {
      return false;
      }
      while (--len >= 0) {
      int c1 = ta[to++];
      int c2 = pa[po++];
      if ((c1 != c2)
      && (!ignoreCase ||
      (c1 > 256) || (c2 > 256) ||
      (trt[c1] != trt[c2]))) {
      return false;
      }
      }
      return true;
          }

        Attachments

          Activity

            People

            • Assignee:
              fyellinsunw Frank Yellin (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: