diff --git a/CHANGES.md b/CHANGES.md index bcef09de84..2c6a2493c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Features Bug Fixes --------- +* [#1087](https://github.com/java-native-access/jna/pull/1087): Fix wrong calls to Structure#toArray with zero sized arrays - [@matthiasblaesing](https://github.com/matthiasblaesing). Release 5.3.0 ============= diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java index 1e18af7ab8..d4a5394e83 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java @@ -670,9 +670,11 @@ public static final WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] getLogicalProce } } WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION firstInformation = new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION( - memory); + memory); + int returnedStructCount = bufferSize.getValue().intValue() + / sizePerStruct; return (WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[]) firstInformation - .toArray(new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[0]); + .toArray(new WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION[returnedStructCount]); } /** diff --git a/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java b/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java index 5db5da0ad5..af942a4c62 100644 --- a/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java +++ b/contrib/platform/src/com/sun/jna/platform/win32/Netapi32Util.java @@ -636,7 +636,7 @@ public static DomainTrust[] getDomainTrusts(String serverName) { } try { DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue()); - DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[0]); + DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]); ArrayList trusts = new ArrayList(domainTrustCount.getValue()); for(DS_DOMAIN_TRUSTS domainTrust : domainTrusts) { DomainTrust t = new DomainTrust(); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java index bd58988d8e..20684a07dc 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Kernel32UtilTest.java @@ -46,6 +46,7 @@ import com.sun.jna.platform.win32.WinNT.NUMA_NODE_RELATIONSHIP; import com.sun.jna.platform.win32.WinNT.PROCESSOR_CACHE_TYPE; import com.sun.jna.platform.win32.WinNT.PROCESSOR_RELATIONSHIP; +import com.sun.jna.platform.win32.WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION; import com.sun.jna.platform.win32.WinNT.SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX; import junit.framework.TestCase; @@ -367,6 +368,12 @@ public void testExpandEnvironmentStrings() { assertEquals("DemoValue", Kernel32Util.expandEnvironmentStrings("%DemoVariable%")); } + public void testGetLogicalProcessorInformation() { + SYSTEM_LOGICAL_PROCESSOR_INFORMATION[] procInfo = Kernel32Util + .getLogicalProcessorInformation(); + assertTrue(procInfo.length > 0); + } + public void testGetLogicalProcessorInformationEx() { SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX[] procInfo = Kernel32Util .getLogicalProcessorInformationEx(WinNT.LOGICAL_PROCESSOR_RELATIONSHIP.RelationAll); diff --git a/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java b/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java index 983886aa7a..3824942ddd 100644 --- a/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java +++ b/contrib/platform/test/com/sun/jna/platform/win32/Netapi32Test.java @@ -260,7 +260,7 @@ public void testDsEnumerateDomainTrusts() { assertTrue(domainTrustCount.getValue() >= 0); DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue()); - DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[0]); + DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]); for (DS_DOMAIN_TRUSTS trust : domainTrusts) { assertTrue(trust.DnsDomainName.length() > 0);