Repository navigation
Map NULL and long C strings to and from String - #84
Merged
Merged
Conversation
A NULL const char * result is returned as null instead of crashing the JVM, a result is read up to its terminator instead of being limited to 1024 bytes, and a null String argument is passed as NULL.
dmlloyd
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
Stringresult or argument now handlesNULLand long strings. ANULLconst char *result is returned asnull; before, the generated code read a C string at address 0 and the JVM crashed with SIGSEGV (getenvof an unset variable). A result is read up to its terminator withreinterpret(Long.MAX_VALUE), as theMemorySegmentdocumentation suggests for strings of unknown length, instead of a 1024-byte segment, which threwIndexOutOfBoundsException: No null terminator foundfor longer strings. AnullStringargument is passed asMemorySegment.NULLinstead of throwingNullPointerExceptionfromallocateFrom, so that parameters which acceptNULL(a query, a default value) can be declared asString. Both changes are inStringResultStepandStringArgumentStepinGenerator.StringNullTestcalls libc:getenvof an unset variable (crashes the test JVM onmain),strcpyof a 5000-character string into a native buffer with the result mapped toString(fails withIndexOutOfBoundsExceptiononmain), andsetlocale(LC_ALL, null)(fails withNullPointerExceptiononmain).mvn verifyon JDK 25 (Linux x86_64): 36 tests, 3 skipped.Stringreturn values: a NULL return crashes the JVM, and returns longer than 1024 bytes throw; anullStringargument throws instead of passing NULL #77