mirror of https://github.com/apache/poi.git
Sonar fix - "Cast one of the operands of this addition operation to a 'long'/'double'"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876767 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
65c8c6cd11
commit
948d4a3574
|
@ -85,7 +85,7 @@ public class Mirr extends MultiOperandNumericFunction {
|
|||
|
||||
private static double mirr(double[] in, double financeRate, double reinvestRate) {
|
||||
double value = 0;
|
||||
double numOfYears = in.length - 1;
|
||||
double numOfYears = in.length - 1.;
|
||||
double pv = 0;
|
||||
double fv = 0;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StreamStore { // TODO - instantiable superclass
|
|||
}
|
||||
|
||||
protected void prependContentsWith(byte[] b) {
|
||||
byte[] newContents = IOUtils.safelyAllocate(contents.length + b.length, MAX_RECORD_LENGTH);
|
||||
byte[] newContents = IOUtils.safelyAllocate(contents.length + (long)b.length, MAX_RECORD_LENGTH);
|
||||
System.arraycopy(b, 0, newContents, 0, b.length);
|
||||
System.arraycopy(contents, 0, newContents, b.length, contents.length);
|
||||
contents = newContents;
|
||||
|
|
|
@ -115,7 +115,7 @@ public class HemfComment {
|
|||
|
||||
@Override
|
||||
public long init(LittleEndianInputStream leis, long recordSize, long recordId) throws IOException {
|
||||
int startIdx = leis.getReadIndex();
|
||||
long startIdx = leis.getReadIndex();
|
||||
data = new EmfCommentDataIterator(leis, (int)recordSize, true).next();
|
||||
return leis.getReadIndex()-startIdx;
|
||||
}
|
||||
|
@ -299,7 +299,7 @@ public class HemfComment {
|
|||
@Override
|
||||
public long init(final LittleEndianInputStream leis, final long dataSize)
|
||||
throws IOException {
|
||||
final int startIdx = leis.getReadIndex();
|
||||
final long startIdx = leis.getReadIndex();
|
||||
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfPlus);
|
||||
new HemfPlusRecordIterator(leis, (int)dataSize-LittleEndianConsts.INT_SIZE).forEachRemaining(records::add);
|
||||
return leis.getReadIndex()-startIdx;
|
||||
|
@ -339,7 +339,7 @@ public class HemfComment {
|
|||
|
||||
@Override
|
||||
public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
|
||||
final int startIdx = leis.getReadIndex();
|
||||
final long startIdx = leis.getReadIndex();
|
||||
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfBeginGroup);
|
||||
HemfDraw.readRectL(leis, bounds);
|
||||
|
||||
|
@ -380,7 +380,7 @@ public class HemfComment {
|
|||
@Override
|
||||
public long init(final LittleEndianInputStream leis, final long dataSize)
|
||||
throws IOException {
|
||||
final int startIdx = leis.getReadIndex();
|
||||
final long startIdx = leis.getReadIndex();
|
||||
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfEndGroup);
|
||||
return leis.getReadIndex()-startIdx;
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ public class HemfComment {
|
|||
}
|
||||
}
|
||||
|
||||
return leis.getReadIndex()-startIdx;
|
||||
return leis.getReadIndex()-(long)startIdx;
|
||||
}
|
||||
|
||||
public List<EmfCommentDataFormat> getFormats() {
|
||||
|
@ -510,7 +510,7 @@ public class HemfComment {
|
|||
throw new RecordFormatException("offset for emrformat must be > 0");
|
||||
}
|
||||
|
||||
return 4*LittleEndianConsts.INT_SIZE;
|
||||
return 4L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
public byte[] getRawData() {
|
||||
|
@ -543,7 +543,7 @@ public class HemfComment {
|
|||
@SuppressWarnings("unused")
|
||||
@Override
|
||||
public long init(final LittleEndianInputStream leis, final long dataSize) throws IOException {
|
||||
final int startIdx = leis.getReadIndex();
|
||||
final long startIdx = leis.getReadIndex();
|
||||
EmfComment.validateCommentType(leis, HemfCommentRecordType.emfWMF);
|
||||
|
||||
// A 16-bit unsigned integer that specifies the WMF metafile version in terms
|
||||
|
|
|
@ -1238,13 +1238,13 @@ public final class HemfDraw {
|
|||
/* A 32-bit signed integer that defines the x coordinate, in logical coordinates,
|
||||
* of the ... corner of the rectangle.
|
||||
*/
|
||||
final int left = leis.readInt();
|
||||
final int top = leis.readInt();
|
||||
final int right = leis.readInt();
|
||||
final int bottom = leis.readInt();
|
||||
final double left = leis.readInt();
|
||||
final double top = leis.readInt();
|
||||
final double right = leis.readInt();
|
||||
final double bottom = leis.readInt();
|
||||
bounds.setRect(left, top, right-left, bottom-top);
|
||||
|
||||
return 4 * LittleEndianConsts.INT_SIZE;
|
||||
return 4L * LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
static long readPointS(LittleEndianInputStream leis, Point2D point) {
|
||||
|
@ -1254,7 +1254,7 @@ public final class HemfDraw {
|
|||
final int y = leis.readShort();
|
||||
point.setLocation(x, y);
|
||||
|
||||
return 2*LittleEndianConsts.SHORT_SIZE;
|
||||
return 2L*LittleEndianConsts.SHORT_SIZE;
|
||||
|
||||
}
|
||||
static long readPointL(LittleEndianInputStream leis, Point2D point) {
|
||||
|
@ -1264,7 +1264,7 @@ public final class HemfDraw {
|
|||
final int y = leis.readInt();
|
||||
point.setLocation(x, y);
|
||||
|
||||
return 2*LittleEndianConsts.INT_SIZE;
|
||||
return 2L*LittleEndianConsts.INT_SIZE;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1272,7 @@ public final class HemfDraw {
|
|||
final double width = leis.readFloat();
|
||||
final double height = leis.readFloat();
|
||||
dimension.setSize(width, height);
|
||||
return 2*LittleEndianConsts.INT_SIZE;
|
||||
return 2L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
static long readDimensionInt(LittleEndianInputStream leis, Dimension2D dimension) {
|
||||
|
@ -1280,7 +1280,7 @@ public final class HemfDraw {
|
|||
final double width = leis.readInt();
|
||||
final double height = leis.readInt();
|
||||
dimension.setSize(width, height);
|
||||
return 2*LittleEndianConsts.INT_SIZE;
|
||||
return 2L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
private static void polyTo(final HemfGraphics ctx, final Path2D poly, FillDrawStyle fillDrawStyle) {
|
||||
|
|
|
@ -509,7 +509,7 @@ public final class HemfFill {
|
|||
long rgnDataSize = leis.readUInt();
|
||||
// A 32-bit unsigned integer that specifies the way to use the region.
|
||||
regionMode = HwmfRegionMode.valueOf((int)leis.readUInt());
|
||||
long size = 2* LittleEndianConsts.INT_SIZE;
|
||||
long size = 2L * LittleEndianConsts.INT_SIZE;
|
||||
|
||||
// If RegionMode is RGN_COPY, this data can be omitted and the clip region
|
||||
// SHOULD be set to the default (NULL) clip region.
|
||||
|
@ -790,7 +790,7 @@ public final class HemfFill {
|
|||
|
||||
final int dibSize = cbBmi+cbBits;
|
||||
if (undefinedSpace2 == 0) {
|
||||
return undefinedSpace1 + bitmap.init(leis, dibSize);
|
||||
return (long)undefinedSpace1 + bitmap.init(leis, dibSize);
|
||||
}
|
||||
|
||||
final ByteArrayOutputStream bos = new ByteArrayOutputStream(cbBmi+cbBits);
|
||||
|
@ -803,7 +803,7 @@ public final class HemfFill {
|
|||
final LittleEndianInputStream leisDib = new LittleEndianInputStream(new ByteArrayInputStream(bos.toByteArray()));
|
||||
final int dibSizeAct = bitmap.init(leisDib, dibSize);
|
||||
assert (dibSizeAct <= dibSize);
|
||||
return undefinedSpace1 + cbBmi + undefinedSpace2 + cbBits;
|
||||
return (long)undefinedSpace1 + cbBmi + undefinedSpace2 + cbBits;
|
||||
}
|
||||
|
||||
|
||||
|
@ -820,7 +820,7 @@ public final class HemfFill {
|
|||
long rgnCntRect = leis.readUInt();
|
||||
// A 32-bit unsigned integer that specifies the size of the buffer of rectangles in bytes.
|
||||
long rgnCntBytes = leis.readUInt();
|
||||
long size = 4*LittleEndianConsts.INT_SIZE;
|
||||
long size = 4L*LittleEndianConsts.INT_SIZE;
|
||||
// A 128-bit WMF RectL object, which specifies the bounds of the region.
|
||||
Rectangle2D rgnBounds = new Rectangle2D.Double();
|
||||
size += readRectL(leis, rgnBounds);
|
||||
|
|
|
@ -360,7 +360,7 @@ public class HemfMisc {
|
|||
colorRef = new HwmfColorRef();
|
||||
int size = colorRef.init(leis);
|
||||
brushHatch = HwmfHatchStyle.valueOf((int) leis.readUInt());
|
||||
return size + 3 * LittleEndianConsts.INT_SIZE;
|
||||
return size + 3L * LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -513,7 +513,7 @@ public class HemfMisc {
|
|||
|
||||
int size = colorRef.init(leis);
|
||||
|
||||
return size + 4 * LittleEndianConsts.INT_SIZE;
|
||||
return size + 4L * LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -792,7 +792,7 @@ public class HemfMisc {
|
|||
// An XForm object that defines a two-dimensional linear transform in logical units.
|
||||
// This transform is used according to the ModifyWorldTransformMode to define a new value for
|
||||
// the world-space to page-space transform in the playback device context.
|
||||
int size = readXForm(leis, xForm);
|
||||
long size = readXForm(leis, xForm);
|
||||
|
||||
// A 32-bit unsigned integer that specifies how the transform specified in Xform is used.
|
||||
// This value MUST be in the ModifyWorldTransformMode enumeration
|
||||
|
|
|
@ -74,7 +74,7 @@ public class HemfPalette {
|
|||
/* A 16-bit unsigned integer that specifies the version number of the system. This MUST be 0x0300. */
|
||||
int version = leis.readUShort();
|
||||
assert(version == 0x0300);
|
||||
int size = readPaletteEntries(leis, -1);
|
||||
long size = readPaletteEntries(leis, -1);
|
||||
return size + LittleEndianConsts.INT_SIZE + LittleEndianConsts.SHORT_SIZE;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class HemfPalette {
|
|||
// A 32-bit unsigned integer that specifies the number of entries.
|
||||
int nbrOfEntries = (int)leis.readUInt();
|
||||
int size = readPaletteEntries(leis, nbrOfEntries);
|
||||
return size + 3*LittleEndianConsts.INT_SIZE;
|
||||
return size + 3L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,7 +170,7 @@ public class HemfPalette {
|
|||
// The value MUST be less than or equal to 0x00000400 and greater than 0x00000000.
|
||||
numberOfEntries = (int)leis.readUInt();
|
||||
|
||||
return 2*LittleEndianConsts.INT_SIZE;
|
||||
return 2L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -311,7 +311,7 @@ public class HemfText {
|
|||
// A 32-bit unsigned integer that specifies the index of the logical font object
|
||||
// in the EMF Object Table
|
||||
fontIdx = (int)leis.readUInt();
|
||||
int size = font.init(leis, (int)(recordSize-LittleEndianConsts.INT_SIZE));
|
||||
long size = font.init(leis, (int)(recordSize-LittleEndianConsts.INT_SIZE));
|
||||
return size+LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
|
|
|
@ -478,7 +478,7 @@ public class HemfPlusBrush {
|
|||
style = EmfPlusHatchStyle.valueOf(leis.readInt());
|
||||
foreColor = readARGB(leis.readInt());
|
||||
backColor = readARGB(leis.readInt());
|
||||
return 3*LittleEndianConsts.INT_SIZE;
|
||||
return 3L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -708,7 +708,7 @@ public final class HemfPlusDraw {
|
|||
// If the CMAP_LOOKUP flag in the optionsFlags field is set, each value in this array specifies a
|
||||
// Unicode character. Otherwise, each value specifies an index to a character glyph in the EmfPlusFont
|
||||
// object specified by the ObjectId value in Flags field.
|
||||
byte[] glyphBuf = IOUtils.toByteArray(leis, glyphCount*2, MAX_OBJECT_SIZE);
|
||||
byte[] glyphBuf = IOUtils.toByteArray(leis, glyphCount*2L, MAX_OBJECT_SIZE);
|
||||
glyphs = StringUtil.getFromUnicodeLE(glyphBuf);
|
||||
|
||||
size += glyphBuf.length;
|
||||
|
|
|
@ -94,7 +94,7 @@ public class HemfPlusHeader implements HemfPlusRecord {
|
|||
|
||||
logicalDpiX = leis.readUInt();
|
||||
logicalDpiY = leis.readUInt();
|
||||
return 4* LittleEndianConsts.INT_SIZE;
|
||||
return 4L*LittleEndianConsts.INT_SIZE;
|
||||
}
|
||||
|
||||
public EmfPlusGraphicsVersion getVersion() {
|
||||
|
|
|
@ -461,7 +461,7 @@ public class HemfPlusMisc {
|
|||
|
||||
origin.setLocation(x,y);
|
||||
|
||||
return LittleEndianConsts.INT_SIZE*2;
|
||||
return LittleEndianConsts.INT_SIZE*2L;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -262,7 +262,7 @@ public class HemfPlusPen {
|
|||
// respect to the width of the EmfPlusPen object that is used to draw the lines.
|
||||
widthScale = leis.readFloat();
|
||||
|
||||
long size = 5*LittleEndianConsts.INT_SIZE;
|
||||
long size = 5L*LittleEndianConsts.INT_SIZE;
|
||||
|
||||
// An EmfPlusPointF object that is not currently used. It MUST be set to {0.0, 0.0}.
|
||||
size += readPointF(leis, fillHotSpot);
|
||||
|
@ -668,7 +668,7 @@ public class HemfPlusPen {
|
|||
// beginning of the line cap and the end of the line.
|
||||
baseInset = leis.readFloat();
|
||||
|
||||
long size = 3*LittleEndianConsts.INT_SIZE;
|
||||
long size = 3L*LittleEndianConsts.INT_SIZE;
|
||||
|
||||
size += super.init(leis);
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public final class DIB extends Bitmap {
|
|||
LittleEndian.putInt(header, 10, offset);
|
||||
|
||||
//DIB data is the header + dib bytes
|
||||
byte[] dib = IOUtils.safelyAllocate(header.length + data.length, MAX_RECORD_LENGTH);
|
||||
byte[] dib = IOUtils.safelyAllocate(header.length + (long)data.length, MAX_RECORD_LENGTH);
|
||||
System.arraycopy(header, 0, dib, 0, header.length);
|
||||
System.arraycopy(data, 0, dib, header.length, data.length);
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public final class WMF extends Metafile {
|
|||
InputStream is = new ByteArrayInputStream( rawdata );
|
||||
Header header = new Header();
|
||||
header.read(rawdata, CHECKSUM_SIZE*getUIDInstanceCount());
|
||||
long skipLen = header.getSize() + CHECKSUM_SIZE*getUIDInstanceCount();
|
||||
long skipLen = header.getSize() + (long)CHECKSUM_SIZE*getUIDInstanceCount();
|
||||
long skipped = IOUtils.skipFully(is, skipLen);
|
||||
assert(skipped == skipLen);
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ public final class DocumentAtom extends RecordAtom {
|
|||
showComments = leis.readByte();
|
||||
|
||||
// If there's any other bits of data, keep them about
|
||||
reserved = IOUtils.safelyAllocate(maxLen-48, MAX_RECORD_LENGTH);
|
||||
reserved = IOUtils.safelyAllocate(maxLen-48L, MAX_RECORD_LENGTH);
|
||||
leis.readFully(reserved);
|
||||
}
|
||||
|
||||
|
|
|
@ -403,7 +403,7 @@ public final class StyleTextPropAtom extends RecordAtom {
|
|||
|
||||
out.append(" original byte stream \n");
|
||||
|
||||
byte[] buf = IOUtils.safelyAllocate(rawContents.length + reserved.length, MAX_RECORD_LENGTH);
|
||||
byte[] buf = IOUtils.safelyAllocate(rawContents.length + (long)reserved.length, MAX_RECORD_LENGTH);
|
||||
System.arraycopy(rawContents, 0, buf, 0, rawContents.length);
|
||||
System.arraycopy(reserved, 0, buf, rawContents.length, reserved.length);
|
||||
out.append( HexDump.dump(buf, 0, 0) );
|
||||
|
|
|
@ -195,7 +195,7 @@ public final class Chunks implements ChunkGroupWithProperties {
|
|||
// Work out what MAPIProperty this corresponds to
|
||||
MAPIProperty prop = MAPIProperty.get(chunk.getChunkId());
|
||||
if (prop == MAPIProperty.UNKNOWN) {
|
||||
long id = (chunk.getChunkId() << 16) + chunk.getType().getId();
|
||||
long id = (chunk.getChunkId() << 16) + (long)chunk.getType().getId();
|
||||
prop = unknownProperties.get(id);
|
||||
if (prop == null) {
|
||||
prop = MAPIProperty.createCustom(chunk.getChunkId(), chunk.getType(), chunk.getEntryName());
|
||||
|
|
|
@ -157,7 +157,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||
if (propertyKind == 1 && propertyNameCRC32[0] < 0) {
|
||||
// skip stream entry matching and return tag from property index from entry stream
|
||||
// this code should not be reached
|
||||
return 0x8000 + propertyIndex;
|
||||
return 0x8000L + propertyIndex;
|
||||
}
|
||||
|
||||
return getPropertyTag(streamID, nameOffset, propertyNameCRC32[0]);
|
||||
|
@ -182,7 +182,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||
int matchPropertyKind = matchGuidIndex & 0x01;
|
||||
|
||||
if (nameCRC == (matchPropertyKind == 0 ? nameOffset : propertyNameCRC32)) {
|
||||
return 0x8000 + matchPropertyIndex;
|
||||
return 0x8000L + matchPropertyIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ public final class NameIdChunks implements ChunkGroup {
|
|||
Consumer<String> propertyNameSetter, Consumer<Long> propertyNameCRC32Setter) {
|
||||
if (propertyKind == 0) {
|
||||
// numerical named property
|
||||
return 0x1000 + (nameOffset ^ (guidIndex << 1)) % 0x1F;
|
||||
return 0x1000L + (nameOffset ^ (guidIndex << 1)) % 0x1F;
|
||||
}
|
||||
|
||||
// string named property
|
||||
|
|
|
@ -453,7 +453,7 @@ public class HwmfBitmapDib implements GenericRecord {
|
|||
int imageSize = (int)Math.max(imageData.length, introSize+headerImageSize);
|
||||
|
||||
// create the image data and leave the parsing to the ImageIO api
|
||||
byte[] buf = IOUtils.safelyAllocate(BMP_HEADER_SIZE + imageSize, MAX_RECORD_LENGTH);
|
||||
byte[] buf = IOUtils.safelyAllocate(BMP_HEADER_SIZE + (long)imageSize, MAX_RECORD_LENGTH);
|
||||
|
||||
// https://en.wikipedia.org/wiki/BMP_file_format # Bitmap file header
|
||||
buf[0] = (byte)'B';
|
||||
|
|
|
@ -197,7 +197,7 @@ public class HwmfText {
|
|||
@Override
|
||||
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException {
|
||||
stringLength = leis.readShort();
|
||||
rawTextBytes = IOUtils.safelyAllocate(stringLength+(stringLength&1), MAX_RECORD_LENGTH);
|
||||
rawTextBytes = IOUtils.safelyAllocate(stringLength+(long)(stringLength&1), MAX_RECORD_LENGTH);
|
||||
leis.readFully(rawTextBytes);
|
||||
// A 16-bit signed integer that defines the vertical (y-axis) coordinate, in logical
|
||||
// units, of the point where drawing is to start.
|
||||
|
@ -413,7 +413,7 @@ public class HwmfText {
|
|||
size += readRectS(leis, bounds);
|
||||
}
|
||||
|
||||
rawTextBytes = IOUtils.safelyAllocate(stringLength+(stringLength&1), MAX_RECORD_LENGTH);
|
||||
rawTextBytes = IOUtils.safelyAllocate(stringLength+(long)(stringLength&1), MAX_RECORD_LENGTH);
|
||||
leis.readFully(rawTextBytes);
|
||||
size += rawTextBytes.length;
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public final class SprmBuffer implements Duplicatable {
|
|||
}
|
||||
|
||||
public SprmBuffer(int sprmsStartOffset) {
|
||||
_buf = IOUtils.safelyAllocate(sprmsStartOffset + 4, MAX_RECORD_LENGTH);
|
||||
_buf = IOUtils.safelyAllocate(sprmsStartOffset + 4L, MAX_RECORD_LENGTH);
|
||||
_offset = sprmsStartOffset;
|
||||
_sprmsStartOffset = sprmsStartOffset;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public final class SprmBuffer implements Duplicatable {
|
|||
// commented - buffer shall not contain any additional bytes --
|
||||
// sergey
|
||||
// byte[] newBuf = new byte[_offset + addition + 6];
|
||||
IOUtils.safelyAllocateCheck(_offset + addition, MAX_RECORD_LENGTH);
|
||||
IOUtils.safelyAllocateCheck(_offset + (long)addition, MAX_RECORD_LENGTH);
|
||||
_buf = Arrays.copyOf(_buf, _offset + addition);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue