Skip to content

fix(libbitcoinkernel-sys): make btck_LogCallback and btck_WriteBytes non-nullable #204

Merged
sedited merged 2 commits into
sedited:masterfrom
alexanderwiederin:non-null
Jul 9, 2026
Merged

fix(libbitcoinkernel-sys): make btck_LogCallback and btck_WriteBytes non-nullable #204
sedited merged 2 commits into
sedited:masterfrom
alexanderwiederin:non-null

Conversation

@alexanderwiederin

@alexanderwiederin alexanderwiederin commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Both types are marked BITCOINKERNEL_ARG_NONNULL in the C Header at every call site, but were bound as Option<unsafe extern "C" fn(...) letting callers pass None, which lowers to a null pointer and is UB in C.

This PR drops the Option wrapper so null is representable at the type level.

Changes

  • btck_LogCallback: bare unsafe extern "C" fn(...). Updated btck_logging_connection_create call site to pass log_callback::<T> instead of Some(log_callback::<T>).
  • btck_WriteBytes: same treatment. Used as the nonnull writer arg in btck_transaction_to_bytes, btck_script_pubkey_to_bytes, btck_block_to_bytes. The c_serialize helper and its call sites already pass the callback unwrapped, so no further changes needed.

Why

Neither type ever had a valid "null" use case.

btck_logging_connection_create marks this arg NONNULL; a null callback
is UB in C.
btck_transaction_to_bytes, btck_script_pubkey_to_bytes and
btck_block_to_bytes mark this arg NONNULL; a null write is UB in C.

@sedited sedited left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 481b055

@sedited sedited merged commit 0cd2676 into sedited:master Jul 9, 2026
13 checks passed
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.

2 participants