Skip to content

Commit

Permalink
[novafinedust] Fix measurement parsing overflow
Browse files Browse the repository at this point in the history
Fixes #12542

Signed-off-by: Stefan Triller <github@stefantriller.de>
  • Loading branch information
t2000 committed Mar 29, 2022
1 parent 4f4dfcc commit 8ea0ca4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public void requestSensorData() throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Read remaining bytes: {}, full reply={}", remainingBytesRead,
HexUtils.bytesToHex(readBuffer));
logger.trace("Read bytes as numbers: {}", Arrays.toString(readBuffer));
}
return ReplyFactory.create(readBuffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean isValidData() {
* @return the measured PM2.5 value
*/
public float getPm25() {
int shiftedValue = (pm25highByte << 8 & 0xFF) | pm25lowByte & 0xFF;
int shiftedValue = ((pm25highByte & 0xFF) << 8) | pm25lowByte & 0xFF;
return ((float) shiftedValue) / 10;
}

Expand All @@ -64,7 +64,7 @@ public float getPm25() {
* @return the measured PM10 value
*/
public float getPm10() {
int shiftedValue = (pm10highByte << 8 & 0xFF) | pm10lowByte & 0xFF;
int shiftedValue = ((pm10highByte & 0xFF) << 8) | pm10lowByte & 0xFF;
return ((float) shiftedValue) / 10;
}

Expand Down

0 comments on commit 8ea0ca4

Please sign in to comment.