Skip to content

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

Merged
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
matthiasblaesing:varargs_fix
Feb 4, 2017
Merged

Fix calling functions with only VarArgs (without fixed parameters)#764
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
matthiasblaesing:varargs_fix

Conversation

@matthiasblaesing
Copy link
Copy Markdown
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
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
Copy Markdown
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
Copy Markdown
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