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
*/
public class LatexCreatorType implements TypeVisitor {
private static final int MAX_LENGTH = 50000;
private final StringBuilder latex = new StringBuilder();
private boolean needsParentheses = false;
@ -80,6 +82,13 @@ public class LatexCreatorType implements TypeVisitor {
latex.append(SPACE);
function.getOutput().accept(this);
checkMemoryUsage();
needsParentheses = true;
}
private void checkMemoryUsage() {
if (latex.length() > MAX_LENGTH) {
throw new IllegalStateException("type too large!");
}
}
}