mirror of https://github.com/apache/poi.git
some int narrowing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903551 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ceb6caa1d5
commit
b8cd360300
|
@ -47,10 +47,10 @@ public abstract class ChunkHeader {
|
|||
} else {
|
||||
ch = new ChunkHeaderV6();
|
||||
}
|
||||
ch.setType((int)LittleEndian.getUInt(data, offset));
|
||||
ch.setId((int)LittleEndian.getUInt(data, offset + 4));
|
||||
ch.setUnknown1((int)LittleEndian.getUInt(data, offset + 8));
|
||||
ch.setLength((int)LittleEndian.getUInt(data, offset + 12));
|
||||
ch.setType(Math.toIntExact(LittleEndian.getUInt(data, offset)));
|
||||
ch.setId(Math.toIntExact(LittleEndian.getUInt(data, offset + 4)));
|
||||
ch.setUnknown1(Math.toIntExact(LittleEndian.getUInt(data, offset + 8)));
|
||||
ch.setLength(Math.toIntExact(LittleEndian.getUInt(data, offset + 12)));
|
||||
ch.setUnknown2(LittleEndian.getShort(data, offset + 16));
|
||||
ch.setUnknown3(LittleEndian.getUByte(data, offset + 18));
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public final class PointerV6 extends Pointer {
|
|||
}
|
||||
public static int getNumPointersOffsetV6(byte[] data) {
|
||||
// V6 stores it as the first value in the stream
|
||||
return (int)LittleEndian.getUInt(data, 0);
|
||||
return Math.toIntExact(LittleEndian.getUInt(data, 0));
|
||||
}
|
||||
/**
|
||||
* 32 bit int at the given offset
|
||||
|
@ -62,7 +62,7 @@ public final class PointerV6 extends Pointer {
|
|||
}
|
||||
public static int getNumPointersV6(int offset, byte[] data) {
|
||||
// V6 stores it a 32 bit number at the offset
|
||||
return (int)LittleEndian.getUInt(data, offset);
|
||||
return Math.toIntExact(LittleEndian.getUInt(data, offset));
|
||||
}
|
||||
/**
|
||||
* 4 bytes of the number, and 4 more unknown bytes
|
||||
|
|
|
@ -433,7 +433,7 @@ public class HemfMisc {
|
|||
int size = 6*LittleEndianConsts.INT_SIZE;
|
||||
|
||||
patternDib = new HwmfBitmapDib();
|
||||
size += readBitmap(leis, patternDib, startIdx, offBmi, cbBmi, offBits, cbBits);
|
||||
size = Math.toIntExact(size + readBitmap(leis, patternDib, startIdx, offBmi, cbBmi, offBits, cbBits));
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -634,9 +634,9 @@ public class HemfMisc {
|
|||
emfPS.setLineDashes(dashPattern);
|
||||
}
|
||||
|
||||
size += numStyleEntries * LittleEndianConsts.INT_SIZE;
|
||||
size = Math.addExact(size, numStyleEntries * LittleEndianConsts.INT_SIZE);
|
||||
|
||||
size += readBitmap(leis, bitmap, startIdx, offBmi, cbBmi, offBits, cbBits);
|
||||
size = Math.toIntExact(size + readBitmap(leis, bitmap, startIdx, offBmi, cbBmi, offBits, cbBits));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -896,11 +896,11 @@ public class HemfMisc {
|
|||
|
||||
// A 32-bit unsigned integer that specifies the size of the DIB bits, if the record
|
||||
// contains a DIB.
|
||||
int cbBits = (int) leis.readUInt();
|
||||
int cbBits = Math.toIntExact(leis.readUInt());
|
||||
|
||||
int size = 6 * LittleEndianConsts.INT_SIZE;
|
||||
|
||||
size += readBitmap(leis, bitmap, startIdx, offBmi, cbBmi, offBits, cbBits);
|
||||
size = Math.toIntExact(size + readBitmap(leis, bitmap, startIdx, offBmi, cbBmi, offBits, cbBits));
|
||||
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -166,19 +166,19 @@ public class HemfText {
|
|||
// invalid dx array
|
||||
dx.clear();
|
||||
}
|
||||
strEnd = (int)recordSize;
|
||||
strEnd = Math.toIntExact(recordSize);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case 's': {
|
||||
int undefinedSpace1 = (int)(offString - (size + HEADER_SIZE));
|
||||
int undefinedSpace1 = Math.toIntExact(offString - (size + HEADER_SIZE));
|
||||
if (offString > 0 && undefinedSpace1 >= 0 && offString-HEADER_SIZE < recordSize) {
|
||||
leis.skipFully(undefinedSpace1);
|
||||
size += undefinedSpace1;
|
||||
|
||||
// read all available bytes and not just "stringLength * 1(ansi)/2(unicode)"
|
||||
// in case we need to deal with surrogate pairs
|
||||
final int maxSize = (int)(Math.min(recordSize, strEnd)-size);
|
||||
final int maxSize = Math.toIntExact(Math.min(recordSize, strEnd)-size);
|
||||
rawTextBytes = IOUtils.safelyAllocate(maxSize, MAX_RECORD_LENGTH);
|
||||
leis.readFully(rawTextBytes);
|
||||
size += maxSize;
|
||||
|
|
|
@ -569,9 +569,9 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
|
|||
case DARKEN_COLOR: {
|
||||
// see java.awt.Color#darken()
|
||||
double FACTOR = (ecr.getRGB()[2])/255.;
|
||||
int r = (int)Math.rint(col.getRed()*FACTOR);
|
||||
int g = (int)Math.rint(col.getGreen()*FACTOR);
|
||||
int b = (int)Math.rint(col.getBlue()*FACTOR);
|
||||
int r = Math.toIntExact(Math.round(col.getRed()*FACTOR));
|
||||
int g = Math.toIntExact(Math.round(col.getGreen()*FACTOR));
|
||||
int b = Math.toIntExact(Math.round(col.getBlue()*FACTOR));
|
||||
return new Color(r,g,b);
|
||||
}
|
||||
case LIGHTEN_COLOR: {
|
||||
|
@ -581,9 +581,9 @@ public abstract class HSLFShape implements Shape<HSLFShape,HSLFTextParagraph> {
|
|||
int g = col.getGreen();
|
||||
int b = col.getBlue();
|
||||
|
||||
r += Math.rint((0xFF-r)*FACTOR);
|
||||
g += Math.rint((0xFF-g)*FACTOR);
|
||||
b += Math.rint((0xFF-b)*FACTOR);
|
||||
r = Math.toIntExact(Math.round(r + (0xFF-r)*FACTOR));
|
||||
g = Math.toIntExact(Math.round(g + (0xFF-g)*FACTOR));
|
||||
b = Math.toIntExact(Math.round(b + (0xFF-b)*FACTOR));
|
||||
|
||||
return new Color(r,g,b);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class RecordUtil
|
|||
|
||||
for ( int x = 0; x < parentSize; x++ )
|
||||
{
|
||||
numBits += ( mask >> x ) & 0x1;
|
||||
numBits += (byte) (( mask >> x ) & 0x1);
|
||||
}
|
||||
|
||||
if ( numBits == 1 )
|
||||
|
|
|
@ -96,7 +96,7 @@ public final class TableSprmUncompressor extends SprmUncompressor {
|
|||
int adjust = sprm.getOperand() - (rgdxaCenter[0] + newTAP.getDxaGapHalf ());
|
||||
for (int x = 0; x < itcMac; x++)
|
||||
{
|
||||
rgdxaCenter[x] += adjust;
|
||||
rgdxaCenter[x] += (short) adjust;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public final class TableSprmUncompressor extends SprmUncompressor {
|
|||
if (rgdxaCenter != null)
|
||||
{
|
||||
int adjust = newTAP.getDxaGapHalf () - sprm.getOperand();
|
||||
rgdxaCenter[0] += adjust;
|
||||
rgdxaCenter[0] += (short) adjust;
|
||||
}
|
||||
newTAP.setDxaGapHalf (sprm.getOperand());
|
||||
break;
|
||||
|
|
|
@ -271,12 +271,12 @@ public abstract class Property implements Child, POIFSViewable {
|
|||
for (; j < limit; j++)
|
||||
{
|
||||
new ShortField(offset, ( short ) char_array[ j ], _raw_data);
|
||||
offset += LittleEndianConsts.SHORT_SIZE;
|
||||
offset += (short) LittleEndianConsts.SHORT_SIZE;
|
||||
}
|
||||
for (; j < _max_name_length + 1; j++)
|
||||
{
|
||||
new ShortField(offset, ( short ) 0, _raw_data);
|
||||
offset += LittleEndianConsts.SHORT_SIZE;
|
||||
offset += (short) LittleEndianConsts.SHORT_SIZE;
|
||||
}
|
||||
|
||||
// double the count, and include the null at the end
|
||||
|
|
|
@ -368,9 +368,9 @@ public class DrawTextParagraph implements Drawable {
|
|||
buSz = 100d;
|
||||
}
|
||||
if (buSz > 0) {
|
||||
fontSize *= buSz* 0.01;
|
||||
fontSize *= (float) (buSz * 0.01);
|
||||
} else {
|
||||
fontSize = (float)-buSz;
|
||||
fontSize = (float) -buSz;
|
||||
}
|
||||
|
||||
String buFontStr = bulletStyle.getBulletFont();
|
||||
|
|
|
@ -694,7 +694,7 @@ public class CellNumberFormatter extends CellFormatter {
|
|||
d = frac.getDenominator();
|
||||
}
|
||||
if (improperFraction) {
|
||||
n += Math.round(value * d);
|
||||
n = Math.toIntExact(n + Math.round(value * d));
|
||||
}
|
||||
writeSingleInteger(numeratorFmt, n, output, numeratorSpecials, mods);
|
||||
writeSingleInteger(denominatorFmt, d, output, denominatorSpecials, mods);
|
||||
|
|
Loading…
Reference in New Issue