java: Make SVWindow more robust (fix three CID issues)

1386093 Division or modulo by zero
1386096 Division or modulo by float zero
1386101 Division or modulo by float zero

A division by zero would have occurred if both sizeX and canvasSizeX or
sizeY and canvasSizeY were 0.

Catch also negative sizes which don't raise a division by zero exception
but which are also invalid.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-04-26 10:02:01 +02:00
parent 64e2efffc7
commit 63d5709958

View File

@ -204,10 +204,20 @@ public class SVWindow extends JFrame {
super(name);
// Provide defaults for sizes.
if (sizeX == 0) sizeX = canvasSizeX;
if (sizeY == 0) sizeY = canvasSizeY;
if (canvasSizeX == 0) canvasSizeX = sizeX;
if (canvasSizeY == 0) canvasSizeY = sizeY;
if (sizeX <= 0) sizeX = canvasSizeX;
if (sizeY <= 0) sizeY = canvasSizeY;
if (canvasSizeX <= 0) canvasSizeX = sizeX;
if (canvasSizeY <= 0) canvasSizeY = sizeY;
// Avoid later division by zero.
if (sizeX <= 0) {
sizeX = 1;
canvasSizeX = sizeX;
}
if (sizeY <= 0) {
sizeY = 1;
canvasSizeY = sizeY;
}
// Initialize variables
nrWindows++;