Skip to content

Commit d7e0f4b

Browse files
authored
Merge pull request #2309 from scadgek/patch-1
Avoid StringIndexOutOfBoundException
2 parents b3f00ca + 96890a3 commit d7e0f4b

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

contributors.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ YYYY/MM/DD, github id, Full name, email
190190
2018/02/11, io7m, Mark Raynsford, [email protected]
191191
2018/04/24, solussd, Joe Smith, [email protected]
192192
2018/15/05, johnvanderholt, jan dillingh [email protected]
193+
2018/06/14, scadgek, Sergey Chupov, [email protected]
193194
2018/06/16, EternalPhane, Zongyuan Zuo, [email protected]
194195
2018/06/27, wu-sheng, Wu Sheng, [email protected]
195196
2018/02/25, chaseoxide, Marcus Ong, taccs97[at]gmail[dot]com
@@ -202,10 +203,10 @@ YYYY/MM/DD, github id, Full name, email
202203
2018/06/16, EternalPhane, Zongyuan Zuo, [email protected]
203204
2018/07/03, jgoppert, James Goppert, [email protected]
204205
2018/07/27, Maksim Novikov, [email protected]
205-
2018/07/31 Lucas Henrqiue, [email protected]
206+
2018/07/31, Lucas Henrqiue, [email protected]
206207
2018/08/03, ENDOH takanao, [email protected]
207208
2018/10/29, chrisaycock, Christopher Aycock, chris[at]chrisaycock[dot]com
208209
2018/11/12, vinoski, Steve Vinoski, [email protected]
209210
2018/11/14, nxtstep, Adriaan (Arjan) Duz, codewithadriaan[et]gmail[dot]com
210211
2018/11/15, amykyta3, Alex Mykyta, [email protected]
211-
2018/11/29, hannemann-tamas, Ralf Hannemann-Tamas, [email protected]
212+
2018/11/29, hannemann-tamas, Ralf Hannemann-Tamas, [email protected]

runtime/Java/src/org/antlr/v4/runtime/CodePointCharStream.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ private CodePoint16BitCharStream(int position, int remaining, String name, char[
203203
/** Return the UTF-16 encoded string for the given interval */
204204
@Override
205205
public String getText(Interval interval) {
206-
int startIdx = Math.min(interval.a, size - 1);
207-
int len = Math.min(interval.b - interval.a + 1, size);
206+
int startIdx = Math.min(interval.a, size);
207+
int len = Math.min(interval.b - interval.a + 1, size - startIdx);
208208

209209
// We know there are no surrogates in this
210210
// array, since otherwise we would be given a
@@ -258,8 +258,8 @@ private CodePoint32BitCharStream(int position, int remaining, String name, int[]
258258
/** Return the UTF-16 encoded string for the given interval */
259259
@Override
260260
public String getText(Interval interval) {
261-
int startIdx = Math.min(interval.a, size - 1);
262-
int len = Math.min(interval.b - interval.a + 1, size);
261+
int startIdx = Math.min(interval.a, size);
262+
int len = Math.min(interval.b - interval.a + 1, size - startIdx);
263263

264264
// Note that we pass the int[] code points to the String constructor --
265265
// this is supported, and the constructor will convert to UTF-16 internally.

0 commit comments

Comments
 (0)