Version
main
Platform
Subsystem
ffi
What steps will reproduce the bug?
repro.c
#include <stddef.h>
#include <string.h>
char* overwrite(char* string, int byte, size_t count) {
return memset(string, byte, count);
}
repro.js
import { DynamicLibrary, suffix, toString } from 'node:ffi';
const lib = new DynamicLibrary(`./repro.${suffix}`);
const overwrite = lib.getFunction('overwrite', {
arguments: ['string', 'i32', 'u64'],
return: 'pointer',
});
console.log(toString(overwrite('hello', 0x79, 1n))); // "yello"
console.log(toString(overwrite('hello', 0, 0n))); // "yello"; expected "hello"
lib.close();
Run commands
$ cc -dynamiclib -o repro.dylib repro.c
$ node --experimental-ffi repro.js
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
each call should populate temporary storage from the supplied JavaScript string, so reusing "hello" should produce "hello".
What do you see instead?
the second call receives "yello" because the cached temporary buffer retains the native mutation from the first call.
Additional information
No response
Version
main
Platform
Subsystem
ffi
What steps will reproduce the bug?
repro.crepro.jsRun commands
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
each call should populate temporary storage from the supplied JavaScript string, so reusing
"hello"should produce"hello".What do you see instead?
the second call receives
"yello"because the cached temporary buffer retains the native mutation from the first call.Additional information
No response