Skip to content

Commit

Permalink
Fix minor IntelliJ warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Aug 13, 2019
1 parent b210bec commit 629dfb2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/main/java/net/fornwall/jelf/ElfDynamicStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ protected ElfStringTable computeValue() throws ElfException, IOException {
public List<String> getNeededLibraries() throws ElfException, IOException {
List<String> 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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/fornwall/jelf/ElfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElfSegment> programHeader : programHeaders) {
ElfSegment ph = programHeader.getValue();
if (ph.type == ElfSegment.PT_INTERP) return ph.getIntepreter();
}
return null;
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/net/fornwall/jelf/ElfHashTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/fornwall/jelf/ElfStringTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 5 additions & 6 deletions src/test/java/net/fornwall/jelf/BasicTest.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 629dfb2

Please sign in to comment.