mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
Make sure we don't try to get code out of bounds
This commit is contained in:
@@ -1144,7 +1144,7 @@ public class PDEX {
|
||||
static private JavaProblem convertIProblem(IProblem iproblem, PreprocessedSketch ps) {
|
||||
SketchInterval in = ps.mapJavaToSketch(iproblem);
|
||||
if (in == SketchInterval.BEFORE_START) return null;
|
||||
String badCode = ps.pdeCode.substring(in.startPdeOffset, in.stopPdeOffset);
|
||||
String badCode = ps.getPdeCode(in);
|
||||
int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset);
|
||||
JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode);
|
||||
p.setPDEOffsets(in.startTabOffset, in.stopTabOffset);
|
||||
@@ -1213,7 +1213,7 @@ public class PDEX {
|
||||
case IProblem.UnterminatedString:
|
||||
SketchInterval in = ps.mapJavaToSketch(iproblem);
|
||||
if (in == SketchInterval.BEFORE_START) continue;
|
||||
String badCode = ps.pdeCode.substring(in.startPdeOffset, in.stopPdeOffset);
|
||||
String badCode = ps.getPdeCode(in);
|
||||
matcher.reset(badCode);
|
||||
while (matcher.find()) {
|
||||
int offset = matcher.start();
|
||||
|
||||
@@ -77,6 +77,14 @@ public class PreprocessedSketch {
|
||||
}
|
||||
|
||||
|
||||
public String getPdeCode(SketchInterval si) {
|
||||
if (si == SketchInterval.BEFORE_START) return "";
|
||||
int stop = Math.min(si.stopPdeOffset, pdeCode.length());
|
||||
int start = Math.min(si.startPdeOffset, stop);
|
||||
return pdeCode.substring(start, stop);
|
||||
}
|
||||
|
||||
|
||||
public SketchInterval mapJavaToSketch(ASTNode node) {
|
||||
return mapJavaToSketch(node.getStartPosition(),
|
||||
node.getStartPosition() + node.getLength());
|
||||
|
||||
Reference in New Issue
Block a user