diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-08-19 02:21:15 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-08-19 02:21:15 +0000 |
commit | b8cd36030001addba4e9f9687308349d5356c789 (patch) | |
tree | 54904ce83289c5f1dfd01a46d36e8002f334d166 /poi-scratchpad/src | |
parent | ceb6caa1d5508f0591e97a1bfe2f48501cb4ebf8 (diff) | |
download | poi-b8cd36030001addba4e9f9687308349d5356c789.tar.gz poi-b8cd36030001addba4e9f9687308349d5356c789.zip |
some int narrowing
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903551 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad/src')
7 files changed, 23 insertions, 23 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java index 068bc0172f..8020d31654 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeader.java @@ -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)); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerV6.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerV6.java index 9983c4ccd4..210e07e3f0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerV6.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/pointers/PointerV6.java @@ -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 diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfMisc.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfMisc.java index 996a44f08e..fb72174e61 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfMisc.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfMisc.java @@ -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; } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java index b7b7ef698c..3b6aaddd75 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java @@ -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; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFShape.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFShape.java index 3b69f66a0f..8dd66e94fe 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFShape.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFShape.java @@ -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); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java index 6c401cc512..6e750da446 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/RecordUtil.java @@ -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 ) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java index 2577bb0515..54cab16890 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmUncompressor.java @@ -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; |