kernel: document that btck_WriteBytes may receive a null pointer #36418

pull alexanderwiederin wants to merge 1 commits into bitcoin:master from alexanderwiederin:kernel-writebytes-nonnull changing 1 files +5 −1
  1. alexanderwiederin commented at 2:22 PM on October 2, 2026: contributor

    The header does not say whether the bytes pointer can be null when size is zero. It can: btck_witness_stack_get_item_at passes std::vector::data() straight through, and that may be null for an empty element.

    An alternative is to guarantee non-null rather than document that it isn't. In other words, route the vector-backed writer calls through a helper that substitutes a valid, never-read pointer when the buffer is empty.

  2. DrahtBot added the label Validation on Oct 2, 2026
  3. DrahtBot commented at 2:22 PM on October 2, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK stickies-v, sedited

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fanquake added this to a project on Oct 2, 2026
  5. github-project-automation[bot] changed the project status on Oct 2, 2026
  6. sedited approved
  7. sedited commented at 10:52 AM on October 6, 2026: contributor

    ACK 76359bee61edb2062493f0ba4ecd47943c359e0a

    Documenting this seems like the correct call, given that developers can, and should probably, already check if the size is zero.

  8. sedited requested review from stickies-v on Oct 7, 2026
  9. in src/kernel/bitcoinkernel.h:394 in 76359bee61
     390 | @@ -391,6 +391,10 @@ typedef void (*btck_ValidationInterfaceBlockDisconnected)(void* user_data, btck_
     391 |  /**
     392 |   * Function signature for serializing data.
     393 |   *
     394 | + * The bytes pointer may be null when size is zero. Callers that construct a
    


    stickies-v commented at 3:33 PM on October 7, 2026:

    Documenting how callers should deal with this seems out of scope, would just describe behaviour. Let's also use more complete Doxygen syntax while we're at it.

    <details> <summary>git diff on 76359bee61</summary>

    diff --git a/src/kernel/bitcoinkernel.h b/src/kernel/bitcoinkernel.h
    index ba6daf72fd..0ada5576a9 100644
    --- a/src/kernel/bitcoinkernel.h
    +++ b/src/kernel/bitcoinkernel.h
    @@ -391,11 +391,11 @@ typedef void (*btck_ValidationInterfaceBlockDisconnected)(void* user_data, btck_
     /**
      * Function signature for serializing data.
      *
    - * The bytes pointer may be null when size is zero. Callers that construct a
    - * language-level slice or array view from the arguments must handle that
    - * case, as some languages require a non-null pointer even for an empty view.
    - *
    - * Returns 0 to indicate success.
    + * [@param](/bitcoin-bitcoin/contributor/param/)[in] bytes    The data to write. Can be null if size is 0.
    + * [@param](/bitcoin-bitcoin/contributor/param/)[in] size     The number of bytes in the data.
    + * [@param](/bitcoin-bitcoin/contributor/param/)[in] userdata Holds the user-defined opaque structure that was given
    + *                     with the writer.
    + * [@return](/bitcoin-bitcoin/contributor/return/)             0 on success.
      */
     typedef int (*btck_WriteBytes)(const void* bytes, size_t size, void* userdata);
     
    
    

    </details>


    alexanderwiederin commented at 5:31 PM on October 7, 2026:

    Taken - thanks!

  10. in src/kernel/bitcoinkernel.h:1 in 76359bee61 outdated


    stickies-v commented at 3:36 PM on October 7, 2026:

    The commit message in 76359be says that this is relevant only to bindings, but I think it also matters to C users, for example when they give bytes to memcpy. I suggest this more general alternative:

    kernel: document that btck_WriteBytes may receive a null pointer
    
    btck_witness_stack_get_item_at passes std::vector::data() to the writer,
    which can be null for an empty witness item. Document this in the contract,
    together with the other btck_WriteBytes parameters.
    

    alexanderwiederin commented at 5:31 PM on October 7, 2026:

    Taken - thanks!

  11. stickies-v commented at 3:39 PM on October 7, 2026: contributor

    Approach ACK, documenting seems like the best choice now.

  12. kernel: document that btck_WriteBytes may receive a null pointer
    btck_witness_stack_get_item_at passes std::vector::data() to the writer,
    which can be null for an empty witness item. Document this in the
    contract, together with the other btck_WriteBytes parameters.
    b497a71c66
  13. alexanderwiederin force-pushed on Oct 7, 2026
  14. stickies-v commented at 5:45 PM on October 7, 2026: contributor

    ACK b497a71c6630fe37f25620f9f08f1c52f9d4d558

  15. DrahtBot requested review from sedited on Oct 7, 2026
  16. sedited approved
  17. sedited commented at 8:17 PM on October 7, 2026: contributor

    ACK b497a71c6630fe37f25620f9f08f1c52f9d4d558

  18. sedited merged this on Oct 7, 2026
  19. sedited closed this on Oct 7, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-27 17:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me