Skip to content

Conversation

bnoordhuis
Copy link
Contributor

JS_ToCStringLen2 returns a pointer to a string that is prefixed by a JSString struct. It lets JS_FreeCString free the memory through simple pointer arithmetic.

JS_ToCStringLen2 has an optimization for ASCII-only 8 bit strings where it returns early but that optimization is not valid for slice strings. They reference their string data indirectly and said data is not prefixed by a JSString.

Fixes: #1178

JS_ToCStringLen2 returns a pointer to a string that is prefixed by a
JSString struct. It lets JS_FreeCString free the memory through simple
pointer arithmetic.

JS_ToCStringLen2 has an optimization for ASCII-only 8 bit strings
where it returns early but that optimization is not valid for slice
strings. They reference their string data indirectly and said data is
not prefixed by a JSString.

Fixes: quickjs-ng#1178
@bnoordhuis bnoordhuis changed the title Make JS_ToCString handle string slices correctly Handle string slices correctly in JS_ToCString Oct 9, 2025
@bnoordhuis bnoordhuis merged commit 62b4eed into quickjs-ng:master Oct 9, 2025
127 checks passed
@bnoordhuis bnoordhuis deleted the fix1178 branch October 9, 2025 23:11
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.

cannot read property of null with no stacktrace on latest head

2 participants