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

Use Java char instead of Java short to pass unsigned WORD values to C functions via JNA #356

Open
klehmann opened this issue Nov 18, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@klehmann
Copy link
Collaborator

Together with core dev we tracked down an issue in our large text list support in 12.0.2 where we had to use a Java char instead of a Java short to work with unsigned C WORD values, here the textSize passed to ListAddEntry2Ext:

int i=0;
for (String currStr : strList) {
	Memory currStrMem = NotesStringUtils.toLMBCS(currStr, false);
	if (currStrMem.size() > 65535) {
		throw new DominoException(MessageFormat.format("List item at position {0} exceeds max lengths of 65535 bytes", i));
	}
			      
	//somehow these two lines produce different results for the ListAddEntry2Ext call with text lengths >32767 bytes
	//leading to an error "Insufficient memory" in macOS when using a short

	//short textSize = (short) (currStrMem==null ? 0 : (currStrMem.size() & 0xffff));
	char textSize = (char) currStrMem.size();
			      
	short addResult = capi1201.ListAddEntry2Ext(hList,
		false,
		retListSize,
		(short) (i & 0xffff),
		currStrMem,
		textSize,
		true);
	NotesErrorUtils.checkResult(addResult);

	i++;
}

ListAddEntry2Ext is declared like this:

STATUS far PASCAL ListAddEntry2Ext(MEMHANDLE mhList,
								BOOL fPrefixDataType,
								DWORD far *pListSize,
								WORD EntryNumber,
								const char far *Text,
								WORD TextSize,
								BOOL bAllowLarge);

To avoid similar issues we should replace all Java shorts in the JNX codebase that are used as unsigned WORD values with a Java char.

@klehmann klehmann added the bug Something isn't working label Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant