Skip to content

Commit

Permalink
check buffer limits
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Feb 13, 2024
1 parent b0bf694 commit 00e33be
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion java/org/jlab/coda/jevio/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ static public void printStackTrace() {
/**
* This method takes a byte buffer and prints out the desired number of words
* from the given position. Will <b>not</b> print out the extra 1, 2, or 3
* bytes left at the end of the buffer.
* bytes left at the end of the buffer. NOT thread-safe.
*
* @param buf buffer to print out
* @param position position of data (bytes) in buffer to start printing
Expand All @@ -591,6 +591,11 @@ static public void printBuffer(ByteBuffer buf, int position, int words, String l
return;
}

if (position >= buf.capacity()) {
System.out.println("position is at or past buffer's capacity");
return;
}

int origPos = buf.position();
int origLim = buf.limit();
// set pos = 0, lim = cap
Expand Down Expand Up @@ -631,6 +636,11 @@ static public void printBytes(ByteBuffer buf, int position, int bytes, String la
return;
}

if (position >= buf.capacity()) {
System.out.println("position is at or past buffer's capacity");
return;
}

int origPos = buf.position();
int origLim = buf.limit();
// set pos = 0, lim = cap
Expand Down

0 comments on commit 00e33be

Please sign in to comment.