opencollab / jlatexmath

A Java API to render LaTeX
Other
514 stars 109 forks source link

Latent NPE in OverUnderBox #99

Open ghost opened 1 year ago

ghost commented 1 year ago

IntelliJ IDEA shows that the following line has a potential fault (script can be null and subsequently dereferenced):

https://github.com/opencollab/jlatexmath/blob/e1bcaa30ae6e73057b9b8d11e54a1ef8929fd299/jlatexmath/src/main/java/org/scilab/forge/jlatexmath/OverUnderBox.java#L96

Whether that fault is ever realized I haven't explored. Here's the fix I added to KeenTeX:

  public OverUnderBox( Box b, Box d, Box script, float kern, boolean over ) {
    base = b;
    del = d;
    this.script = script;
    this.kern = kern;
    this.over = over;

    // Kerned height.
    final var kh = script == null ? 0 : script.height + script.depth + kern;

    // calculate metrics of the box
    width = b.getWidth();
    height = b.height
      + (over ? d.getWidth() : 0)
      + (over && script != null ? kh : 0);
    depth = b.depth
      + (over ? 0 : d.getWidth())
      + (!over && script == null ? 0 : kh);
  }