fix(data): Allocate empty array on tw_data_create_with_bytes if data is NULL
#4508
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.
This pull request refactors memory handling in the Rust FFI layer to simplify error handling and improve API consistency. The main change is that methods like
CByteArrayRef::to_vec()andCByteArrayRef::as_slice()now always return a value (empty if pointer is NULL), instead of anOption. Additionally, a new test is added for Ethereum Barz authorization with an empty-array representation of zero nonce.Memory API refactoring
rust/tw_memory/src/ffi/c_byte_array_ref.rs: ChangedCByteArrayRef::to_vec()andCByteArrayRef::as_slice()to always return a value (empty on invalid input), removingOptionfrom their signatures. [1] [2]rust/tw_memory/src/ffi/tw_data.rs: UpdatedTWData::from_raw_data()to always return aTWDataand refactoredtw_data_create_with_bytes()to remove error handling for null pointers. [1] [2]rust/tw_memory/src/ffi/tw_string.rs: SimplifiedTWString::is_utf8_string()to remove error handling for invalid input.FFI function simplification
rust/tw_keypair/src/ffi/privkey.rs,rust/tw_keypair/src/ffi/pubkey.rs,rust/tw_keypair/src/ffi/asn.rs: Removed error-handling macros (try_or_else!,try_or_false!) from FFI functions, relying on the new memory API to return empty values on invalid input instead. [1] [2] [3] [4] [5] [6]Testing improvements
tests/chains/Ethereum/BarzTests.cpp: Added a new test case for signing Ethereum Barz authorization with a zero nonce to verify correct handling of empty nonce input.