compiler: Allow string slices with start index == length.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Aug 2015 20:31:51 +0000 (20:31 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Aug 2015 20:31:51 +0000 (20:31 +0000)
    Avoid an off-by-one error when checking the start index of a string
    slice by allowing the start index to be the string length instead
    of the string length - 1.

    Fixes golang/go#11522.

    Reviewed-on: https://go-review.googlesource.com/13030

From-SVN: r227191

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc

index 1bde6690e2a6b061cde994bac664b3333dd17229..86d163b1f52fcde891835cbe3d7d78ea9c6403ee 100644 (file)
@@ -1,4 +1,4 @@
-d6d59d5927c4ea0c02468ebc6a2df431fb64595a
+14ca4b6130b9a7132d132f418e9ea283b3a52c08
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index c0e5fc53a82271262a087958bfcfdc314e8cd21e..f1873cd396c3f141714dab2dfe5f4607fc9472c0 100644 (file)
@@ -10341,7 +10341,10 @@ String_index_expression::do_check_types(Gogo*)
     {
       ival_valid = true;
       if (mpz_sgn(ival) < 0
-         || (sval_valid && mpz_cmp_ui(ival, sval.length()) >= 0))
+         || (sval_valid
+             && (this->end_ == NULL
+                 ? mpz_cmp_ui(ival, sval.length()) >= 0
+                 : mpz_cmp_ui(ival, sval.length()) > 0)))
        {
          error_at(this->start_->location(), "string index out of bounds");
          this->set_is_error();