Skip to content

Commit 9369d40

Browse files
committed
Combine size checks
1 parent 6a294f9 commit 9369d40

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

app/src/main/java/com/samsung/microbit/utils/FileUtils.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ public static byte[] readBytesFromFile( File file) {
226226
byte[] bytes = null;
227227
try {
228228
long size = file.length();
229-
if ( size > Integer.MAX_VALUE) {
230-
Log.e( TAG, "readBytesFromFile too big");
231-
return null;
232-
}
233-
if ( size <= 0) {
234-
Log.e( TAG, "readBytesFromFile size unknown");
229+
if ( size <= 0 || size > Integer.MAX_VALUE) {
230+
Log.e( TAG, "readBytesFromFile error - size");
235231
return null;
236232
}
237233
FileInputStream is = new FileInputStream( file);
@@ -249,12 +245,8 @@ public static byte[] readBytesFromUri( Uri uri, Context ctx) {
249245
byte[] bytes = null;
250246
try {
251247
long size = fileSizeFromUri( uri, ctx);
252-
if ( size > Integer.MAX_VALUE) {
253-
Log.e( TAG, "readBytesFromUri too big");
254-
return null;
255-
}
256-
if ( size <= 0) {
257-
Log.e( TAG, "readBytesFromUri size unknown");
248+
if ( size <= 0 || size > Integer.MAX_VALUE) {
249+
Log.e( TAG, "readBytesFromUri error - size");
258250
return null;
259251
}
260252
InputStream is = ctx.getContentResolver().openInputStream( uri);

0 commit comments

Comments
 (0)