Skip to content

Commit d225103

Browse files
committed
fixup! test: avoid dangling FFI string pointer
1 parent f73ee95 commit d225103

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

test/ffi/fixture_library/ffi_test_library.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ FFI_EXPORT uint8_t string_equals_hello(const char* str) {
108108
return str && strcmp(str, "hello") == 0;
109109
}
110110

111-
FFI_EXPORT char* overwrite_string(char* str, int32_t value, uint64_t length) {
112-
return memset(str, value, (size_t)length);
111+
FFI_EXPORT uint8_t overwrite_string(char* str,
112+
int32_t value,
113+
uint64_t length) {
114+
memset(str, value, (size_t)length);
115+
return (uint8_t)str[0];
113116
}
114117

115118
FFI_EXPORT char* string_concat(const char* a, const char* b) {

test/ffi/test-ffi-fast-buffer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ test('fast FFI refreshes cached temporary string buffers', () => {
100100
const lib = new ffi.DynamicLibrary(libraryPath);
101101
const overwriteString = lib.getFunction('overwrite_string', {
102102
arguments: ['string', 'i32', 'u64'],
103-
return: 'pointer',
103+
return: 'u8',
104104
});
105105

106106
try {
107107
const mutated = overwriteString('hello', 0x79, 1n);
108-
assert.strictEqual(ffi.toString(mutated), 'yello');
108+
assert.strictEqual(mutated, 0x79);
109109

110110
const refreshed = overwriteString('hello', 0x79, 0n);
111-
assert.strictEqual(ffi.toString(refreshed), 'hello');
111+
assert.strictEqual(refreshed, 0x68);
112112
} finally {
113113
lib.close();
114114
}

0 commit comments

Comments
 (0)