Skip to content

Commit b5d6258

Browse files
committed
Merge #255: fix: use unsigned char cast and sizeof in LogEscape escape sequence
554a481 fix: use unsigned char cast and sizeof in LogEscape escape sequence (Mangoostaa) Pull request description: 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. ACKs for top commit: ryanofsky: Code review ACK 554a481. Signed fix and sizeof cleanup both makes sense. Nice catch! Tree-SHA512: 5a19b3caf4b371a363ed7f5151871e306c91c8e4bf180e7df530a562298b924c8a8e213d82069e580dc9d474bcddc7455d842849d7b50152d6eb29aa1f6e97c0
2 parents d94688e + 554a481 commit b5d6258

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/mp/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ std::string LogEscape(const kj::StringTree& string, size_t max_size)
102102
result.append("\\\\");
103103
} else if (c < 0x20 || c > 0x7e) {
104104
char escape[4];
105-
snprintf(escape, 4, "\\%02x", c);
105+
snprintf(escape, sizeof(escape), "\\%02x", static_cast<unsigned char>(c));
106106
result.append(escape);
107107
} else {
108108
result.push_back(c);

0 commit comments

Comments
 (0)