From 629dfb20e34dfce2a565a87ca4a1f7df041423b8 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 13 Aug 2019 22:29:38 +0200 Subject: [PATCH] Fix minor IntelliJ warnings --- .../fornwall/jelf/ElfDynamicStructure.java | 3 +-- src/main/java/net/fornwall/jelf/ElfFile.java | 4 ++-- .../java/net/fornwall/jelf/ElfHashTable.java | 20 ++++++------------- .../net/fornwall/jelf/ElfStringTable.java | 3 +-- .../java/net/fornwall/jelf/BasicTest.java | 11 +++++----- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/fornwall/jelf/ElfDynamicStructure.java b/src/main/java/net/fornwall/jelf/ElfDynamicStructure.java index 2365fd2..cebe898 100644 --- a/src/main/java/net/fornwall/jelf/ElfDynamicStructure.java +++ b/src/main/java/net/fornwall/jelf/ElfDynamicStructure.java @@ -185,8 +185,7 @@ protected ElfStringTable computeValue() throws ElfException, IOException { public List getNeededLibraries() throws ElfException, IOException { List result = new ArrayList<>(); ElfStringTable stringTable = dtStringTable.getValue(); - for (int i = 0; i < dtNeeded.length; i++) - result.add(stringTable.get(dtNeeded[i])); + for (int value : dtNeeded) result.add(stringTable.get(value)); return result; } diff --git a/src/main/java/net/fornwall/jelf/ElfFile.java b/src/main/java/net/fornwall/jelf/ElfFile.java index 05f256e..20671c2 100644 --- a/src/main/java/net/fornwall/jelf/ElfFile.java +++ b/src/main/java/net/fornwall/jelf/ElfFile.java @@ -430,8 +430,8 @@ public ElfSegment computeValue() throws IOException { /** The interpreter specified by the {@link ElfSegment#PT_INTERP} program header, if any. */ public String getInterpreter() throws IOException { - for (int i = 0; i < programHeaders.length; i++) { - ElfSegment ph = programHeaders[i].getValue(); + for (MemoizedObject programHeader : programHeaders) { + ElfSegment ph = programHeader.getValue(); if (ph.type == ElfSegment.PT_INTERP) return ph.getIntepreter(); } return null; diff --git a/src/main/java/net/fornwall/jelf/ElfHashTable.java b/src/main/java/net/fornwall/jelf/ElfHashTable.java index 43b0c60..91e7661 100644 --- a/src/main/java/net/fornwall/jelf/ElfHashTable.java +++ b/src/main/java/net/fornwall/jelf/ElfHashTable.java @@ -2,24 +2,16 @@ public class ElfHashTable { - /** - * Returns the ELFSymbol that has the specified name or null if no symbol with that name exists. NOTE: Currently - * this method does not work and will always return null. - */ - private int num_buckets; - private int num_chains; - - // These could probably be memoized. - private int buckets[]; - private int chains[]; ElfHashTable(ElfParser parser, long offset, int length) { parser.seek(offset); - num_buckets = parser.readInt(); - num_chains = parser.readInt(); - buckets = new int[num_buckets]; - chains = new int[num_chains]; + int num_buckets = parser.readInt(); + int num_chains = parser.readInt(); + + // These could probably be memoized. + int[] buckets = new int[num_buckets]; + int[] chains = new int[num_chains]; // Read the bucket data. for (int i = 0; i < num_buckets; i++) { buckets[i] = parser.readInt(); diff --git a/src/main/java/net/fornwall/jelf/ElfStringTable.java b/src/main/java/net/fornwall/jelf/ElfStringTable.java index a8cf2de..99f0999 100644 --- a/src/main/java/net/fornwall/jelf/ElfStringTable.java +++ b/src/main/java/net/fornwall/jelf/ElfStringTable.java @@ -17,8 +17,7 @@ public final class ElfStringTable { throw new ElfException("Error reading string table (read " + bytesRead + "bytes - expected to " + "read " + data.length + "bytes)"); int stringsCount = 0; - for (int ptr = 0; ptr < data.length; ptr++) - if (data[ptr] == '\0') stringsCount++; + for (byte datum : data) if (datum == '\0') stringsCount++; numStrings = stringsCount; } diff --git a/src/test/java/net/fornwall/jelf/BasicTest.java b/src/test/java/net/fornwall/jelf/BasicTest.java index 802855c..a59f7ef 100644 --- a/src/test/java/net/fornwall/jelf/BasicTest.java +++ b/src/test/java/net/fornwall/jelf/BasicTest.java @@ -1,13 +1,12 @@ package net.fornwall.jelf; -import java.io.File; +import org.junit.Assert; +import org.junit.Test; + import java.io.FileNotFoundException; import java.io.IOException; import java.util.Arrays; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import java.util.Collections; public class BasicTest { @@ -122,7 +121,7 @@ public void testLinxAmd64BinDash() throws ElfException, FileNotFoundException, I assertSectionNames(file, null, ".interp", ".note.ABI-tag", ".note.gnu.build-id", ".gnu.hash", ".dynsym"); ElfDynamicStructure ds = file.getDynamicLinkSection().getDynamicSection(); - Assert.assertEquals(Arrays.asList("libc.so.6"), ds.getNeededLibraries()); + Assert.assertEquals(Collections.singletonList("libc.so.6"), ds.getNeededLibraries()); Assert.assertEquals("/lib64/ld-linux-x86-64.so.2", file.getInterpreter()); }