Skip to content

Commit

Permalink
InputStream integer return fixes.
Browse files Browse the repository at this point in the history
Fix one condition where read returns a large negative integer instead of the correct byte value. 
Fix a second condition where checkFromBuffer returns a negative number and triggers a serial read before the buffer is depleted.

For example, if 0xFE is read, 0xFFFFFFFE is returned from the buffer which is out of the byte range.
  • Loading branch information
twsmith85 authored Dec 20, 2018
1 parent 4d4695c commit 13a6cfc
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public int read()
int ret = device.syncRead(buffer, timeout);
if(ret >= 0) {
bufferSize = ret;
return buffer[pointer++];
return buffer[pointer++] & 0xff;
}else {
return -1;
}
Expand All @@ -68,7 +68,7 @@ public void setTimeout(int timeout) {

private int checkFromBuffer(){
if(bufferSize > 0 && pointer < bufferSize){
return buffer[pointer++];
return buffer[pointer++] & 0xff;
}else{
pointer = 0;
bufferSize = -1;
Expand Down

0 comments on commit 13a6cfc

Please sign in to comment.