From 804353e21776d76c763a4810d55ff04ccc3be530 Mon Sep 17 00:00:00 2001 From: Sergey Chupov Date: Thu, 14 Jun 2018 16:03:17 +0300 Subject: [PATCH 1/3] Avoid StringIndexOutOfBoundException This fixes https://github.com/antlr/antlr4/issues/2138#issuecomment-397271786. Clearly it's been an oversight, since the same code has been fixed for CodePoint8Bit in this commit: https://github.com/antlr/antlr4/commit/ac9f75303e215dbc12937eba68089151aef6f874 --- .../src/org/antlr/v4/runtime/CodePointCharStream.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java index 107faa7b1..241354556 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java @@ -203,8 +203,8 @@ public abstract class CodePointCharStream implements CharStream { /** Return the UTF-16 encoded string for the given interval */ @Override public String getText(Interval interval) { - int startIdx = Math.min(interval.a, size - 1); - int len = Math.min(interval.b - interval.a + 1, size); + int startIdx = Math.min(interval.a, size); + int len = Math.min(interval.b - interval.a + 1, size - startIdx); // We know there are no surrogates in this // array, since otherwise we would be given a @@ -258,8 +258,8 @@ public abstract class CodePointCharStream implements CharStream { /** Return the UTF-16 encoded string for the given interval */ @Override public String getText(Interval interval) { - int startIdx = Math.min(interval.a, size - 1); - int len = Math.min(interval.b - interval.a + 1, size); + int startIdx = Math.min(interval.a, size); + int len = Math.min(interval.b - interval.a + 1, size - startIdx); // Note that we pass the int[] code points to the String constructor -- // this is supported, and the constructor will convert to UTF-16 internally. From 2e4280944d1d942114f4aebbbafdf54a07ad6397 Mon Sep 17 00:00:00 2001 From: Sergey Chupov Date: Thu, 14 Jun 2018 16:08:58 +0300 Subject: [PATCH 2/3] add my entry to contributors --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index a55a31707..6af243bcd 100644 --- a/contributors.txt +++ b/contributors.txt @@ -182,3 +182,4 @@ YYYY/MM/DD, github id, Full name, email 2017/12/27, jkmar, Jakub Marciniszyn, marciniszyn.jk@gmail.com 2018/02/11, io7m, Mark Raynsford, code@io7m.com 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com +2018/14/06, scadgek, Sergey Chupov, scadgek@live.com From 9321b6bb97b9d1a9d6644817da9ca3ba99af39b4 Mon Sep 17 00:00:00 2001 From: Sergey Chupov Date: Mon, 12 Nov 2018 11:01:18 +0200 Subject: [PATCH 3/3] Update contributors.txt --- contributors.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/contributors.txt b/contributors.txt index 04022bf73..f2bbe7194 100644 --- a/contributors.txt +++ b/contributors.txt @@ -191,7 +191,6 @@ YYYY/MM/DD, github id, Full name, email 2018/15/05, johnvanderholt, jan dillingh johnvanderholte@gmail.com 2018/06/14, scadgek, Sergey Chupov, scadgek@live.com 2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com -2018/06/16, EternalPhane, Zongyuan Zuo, eternalphane@gmail.com 2018/06/27, wu-sheng, Wu Sheng, wu.sheng@foxmail.com 2018/02/25, chaseoxide, Marcus Ong, taccs97[at]gmail[dot]com 2018/05/15, johnvanderholt, jan dillingh johnvanderholte@gmail.com