Skip to content

Commit

Permalink
Use correct bit masks when extracting low/high word from DWORD
Browse files Browse the repository at this point in the history
This is a regression introduced by commit 

4218a07

The applied bit masks a 8 bit value, while word is 16 bit sized.

Closes: #624
  • Loading branch information
matthiasblaesing committed Jul 22, 2016
1 parent 6c52731 commit c58d756
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Bug Fixes
* [#646](https://github.com/java-native-access/jna/issues/646): `platform.win32.COM.COMBindingBaseObject` swallows reason if instantiation fails - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#674](https://github.com/java-native-access/jna/pull/674): Update references to Apache License as requested by issue #673 [@bhamail](https://github.com/bhamail)
* [#636](https://github.com/java-native-access/jna/issues/636): Staticly link visual c++ runtime when building with MSVC - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#624](https://github.com/java-native-access/jna/issues/624): WinDef.DWORD getLow() & getHigh() using incorrect bit mask - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 4.2.1
=============
Expand Down
4 changes: 2 additions & 2 deletions contrib/platform/src/com/sun/jna/platform/win32/WinDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public DWORD(long value) {
* @return Low WORD.
*/
public WORD getLow() {
return new WORD(longValue() & 0xFF);
return new WORD(longValue() & 0xFFFF);
}

/**
Expand All @@ -148,7 +148,7 @@ public WORD getLow() {
* @return High WORD.
*/
public WORD getHigh() {
return new WORD((longValue() >> 16) & 0xFF);
return new WORD((longValue() >> 16) & 0xFFFF);
}

@Override
Expand Down
44 changes: 44 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/win32/WinDefTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

package com.sun.jna.platform.win32;

import com.sun.jna.platform.win32.WinDef.DWORD;
import com.sun.jna.platform.win32.WinDef.WORD;
import org.junit.Test;
import static org.junit.Assert.*;

public class WinDefTest {

@Test
public void testWordExtractionFromDword() {
DWORD dword = new DWORD(0x12345678);

assertEquals(new WORD(0x5678), dword.getLow());
assertEquals(new WORD(0x1234), dword.getHigh());

DWORD dword2 = new DWORD(0xFFFFFFFF);

assertEquals(new WORD(0xFFFF), dword2.getLow());
assertEquals(new WORD(0xFFFF), dword2.getHigh());

DWORD dword3 = new DWORD(0x00000001);

assertEquals(new WORD(0x0001), dword3.getLow());
assertEquals(new WORD(0x0000), dword3.getHigh());

DWORD dword4 = new DWORD(0x00010000);

assertEquals(new WORD(0x0000), dword4.getLow());
assertEquals(new WORD(0x0001), dword4.getHigh());

DWORD dword5 = new DWORD(0x0000FFFF);

assertEquals(new WORD(0xFFFF), dword5.getLow());
assertEquals(new WORD(0x0000), dword5.getHigh());

DWORD dword6 = new DWORD(0xFFFF0000);

assertEquals(new WORD(0x0000), dword6.getLow());
assertEquals(new WORD(0xFFFF), dword6.getHigh());
}

}

0 comments on commit c58d756

Please sign in to comment.