Limit memory usage of LatexCreatorType

This commit is contained in:
Arne Keller 2021-03-10 16:07:20 +01:00
parent 08b80257e2
commit 4c0eb78300

View File

@ -15,6 +15,8 @@ import static edu.kit.typicalc.view.content.typeinferencecontent.latexcreator.La
* @see Type * @see Type
*/ */
public class LatexCreatorType implements TypeVisitor { public class LatexCreatorType implements TypeVisitor {
private static final int MAX_LENGTH = 50000;
private final StringBuilder latex = new StringBuilder(); private final StringBuilder latex = new StringBuilder();
private boolean needsParentheses = false; private boolean needsParentheses = false;
@ -80,6 +82,13 @@ public class LatexCreatorType implements TypeVisitor {
latex.append(SPACE); latex.append(SPACE);
function.getOutput().accept(this); function.getOutput().accept(this);
checkMemoryUsage();
needsParentheses = true; needsParentheses = true;
} }
private void checkMemoryUsage() {
if (latex.length() > MAX_LENGTH) {
throw new IllegalStateException("type too large!");
}
}
} }