Skip to content

Conversation

@jesterhodl
Copy link
Contributor

This attempts to fix #30 by:

  • consolidating read_u32_le(), read_u64_le(), write_u32_le(), write_u64_le()
  • renames them to deserialize/serialize to avoid conflicts with protocol/serialize.c functions with the same name, but different type and signature
  • removes UBSan bug from deserialize_header() by using deserialize_u32_le()

jesterhodl and others added 2 commits January 7, 2026 14:09
Move deserialize_u32/64_le and serialize_u32/64_le implementations from
serialize.c to serialize.h as static inline functions. These tiny helpers
benefit from inlining to avoid function call overhead on hot paths during
block sync.

Co-authored-by: JesterHodl <jesterhodl@jesterhodl.com>
@sethatwood sethatwood force-pushed the fix-undefined-behavior-in-deserialize_header branch from bdd5601 to 3c7c933 Compare January 7, 2026 19:13
@sethatwood sethatwood merged commit 5c7468c into bitcoinecho:main Jan 7, 2026
2 checks passed
@sethatwood
Copy link
Member

Thanks for this contribution! The UB fix and consolidation are exactly right.

We added one small refinement on top: making the helpers static inline in the header rather than regular functions in the .c file. These are tiny operations called millions of times during sync, so inlining avoids function call overhead on hot paths.

Appreciate you catching the UBSan issue and taking the initiative to clean up the duplication!

sethatwood added a commit that referenced this pull request Jan 7, 2026
This attempts to fix #30 by:
- consolidating `read_u32_le()`, `read_u64_le()`, `write_u32_le()`,
`write_u64_le()`
- renames them to `deserialize`/`serialize` to avoid conflicts with
`protocol/serialize.c` functions with the same name, but different type
and signature
- removes UBSan bug from `deserialize_header()` by using
`deserialize_u32_le()`

---------

Co-authored-by: Seth Atwood <sethmerrick@gmail.com>
@jesterhodl jesterhodl deleted the fix-undefined-behavior-in-deserialize_header branch January 8, 2026 19:17
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.

src/storage/block_index_db.c:242:67: runtime error: left shift of 153 by 24 places cannot be represented in type 'int'

2 participants