Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling functions with only VarArgs (without fixed parameters) #764

Merged

Conversation

matthiasblaesing
Copy link
Member

The change in 50eb820 introduces
the detection of the count of the fixed parameters of a VarArgs call.

The logic detecting whether this call was even a VarArgs call was
changed to be true if fixed parameter count is not null. This is
not correct, as the method call could contain only fixed parameters
or a VarArgs call could be done without fixed parameters.

Closes: #763

The change in 50eb820 introduces
the detection of the count of the fixed parameters of a VarArgs call.

The logic detecting whether this call was even a VarArgs call was
changed to be true if fixed parameter count is not null. This is
not correct, as the method call could contain only fixed parameters
or a VarArgs call could be done without fixed parameters.

Closes: java-native-access#763
@@ -43,6 +43,7 @@
public int addVarArgs(String fmt, Number... args);
public String returnStringVarArgs(String fmt, Object... args);
public void modifyStructureVarArgs(String fmt, Object arg1, Object... args);
public String returnStringVarArgs(String... args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Varargs with no fixed arguments aren't possible in C (though they may be in other languages). In C you'd have to directly access the stack pointer to find the address of arguments, which may be compiler or processor-dependent.

public void testStringVarArgsFull() {
Object[] args = new Object[] { "Test" };
assertEquals("Did not return correct string", args[0],
lib.returnStringVarArgs("", "Test"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'd want to test passing no arguments here. Perhaps this "bug" is an issue with the client (java) code?

@matthiasblaesing matthiasblaesing merged commit 68bd600 into java-native-access:master Feb 4, 2017
@matthiasblaesing matthiasblaesing deleted the varargs_fix branch March 26, 2017 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayIndexOutOfBoundsException with JNA 4.3.0
2 participants