From 3623842827b87d886ab74de2737fddb28db0da41 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 12 Jan 2025 03:10:44 +0200 Subject: [PATCH] sanitize Source.loc argument --- .../src/main/java/me/topchetoeu/j2s/common/parsing/Source.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java index 531778e..abd3c92 100644 --- a/common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java +++ b/common/src/main/java/me/topchetoeu/j2s/common/parsing/Source.java @@ -12,6 +12,8 @@ public class Source { private int[] lineStarts; public Location loc(int offset) { + if (offset < 0) offset = 0; + if (offset > src.length()) offset = src.length(); return new SourceLocation(filename, lineStarts, offset); } public boolean is(int i, char c) {