Skip to content

fix: use unsigned char cast and sizeof in LogEscape escape sequence#255

Open
mangoostaa wants to merge 1 commit intobitcoin-core:masterfrom
mangoostaa:fix/logescape-snprintf
Open

fix: use unsigned char cast and sizeof in LogEscape escape sequence#255
mangoostaa wants to merge 1 commit intobitcoin-core:masterfrom
mangoostaa:fix/logescape-snprintf

Conversation

@mangoostaa
Copy link

Found a small correctness issue in LogEscape():

  • When char is signed (common on x86_64 Linux), negative byte values
    (e.g. 0xFF = -1) were being printed as ffffffff instead of ff.

  • This fixes it by casting to unsigned char before %02x.

  • Also changed the hardcoded 4 to sizeof(escape) so the code doesn't
    break silently if someone increases the buffer size later.

No performance impact, just safer and more portable.

@DrahtBot
Copy link

DrahtBot commented Mar 12, 2026

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

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

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