Skip to content

Commit 3608442

Browse files
committed
std: Deprecate 'x'/'X'/'e'/'E' special cases for u8 slices
Let's follow the road paved by the removal of 'z'/'Z', the Formatter pattern is nice enough to let us remove the remaining four special cases and declare u8 slices free from any special casing!
1 parent 0aef1fa commit 3608442

File tree

9 files changed

+145
-46
lines changed

9 files changed

+145
-46
lines changed

lib/std/crypto/25519/curve25519.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ test "curve25519" {
115115
const p = try Curve25519.basePoint.clampedMul(s);
116116
try p.rejectIdentity();
117117
var buf: [128]u8 = undefined;
118-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{p.toBytes()}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
118+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
119119
const q = try p.clampedMul(s);
120-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{q.toBytes()}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
120+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
121121

122122
try Curve25519.rejectNonCanonical(s);
123123
s[31] |= 0x80;

lib/std/crypto/25519/ed25519.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ test "ed25519 key pair creation" {
210210
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
211211
const key_pair = try Ed25519.KeyPair.create(seed);
212212
var buf: [256]u8 = undefined;
213-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{key_pair.secret_key}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
214-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{key_pair.public_key}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
213+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.secret_key)}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
214+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&key_pair.public_key)}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
215215
}
216216

217217
test "ed25519 signature" {
@@ -221,7 +221,7 @@ test "ed25519 signature" {
221221

222222
const sig = try Ed25519.sign("test", key_pair, null);
223223
var buf: [128]u8 = undefined;
224-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{sig}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
224+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&sig)}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
225225
try Ed25519.verify(sig, "test", key_pair.public_key);
226226
std.testing.expectError(error.InvalidSignature, Ed25519.verify(sig, "TEST", key_pair.public_key));
227227
}

lib/std/crypto/25519/edwards25519.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ test "edwards25519 packing/unpacking" {
450450
var b = Edwards25519.basePoint;
451451
const pk = try b.mul(s);
452452
var buf: [128]u8 = undefined;
453-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{pk.toBytes()}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
453+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&pk.toBytes())}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
454454

455455
const small_order_ss: [7][32]u8 = .{
456456
.{

lib/std/crypto/25519/ristretto255.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,21 @@ pub const Ristretto255 = struct {
170170
test "ristretto255" {
171171
const p = Ristretto255.basePoint;
172172
var buf: [256]u8 = undefined;
173-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{p.toBytes()}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
173+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&p.toBytes())}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
174174

175175
var r: [Ristretto255.encoded_length]u8 = undefined;
176176
_ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
177177
var q = try Ristretto255.fromBytes(r);
178178
q = q.dbl().add(p);
179-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
179+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&q.toBytes())}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
180180

181181
const s = [_]u8{15} ++ [_]u8{0} ** 31;
182182
const w = try p.mul(s);
183-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
183+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&w.toBytes())}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
184184

185185
std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
186186

187187
const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32;
188188
const ph = Ristretto255.fromUniform(h);
189-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
189+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ph.toBytes())}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
190190
}

lib/std/crypto/25519/scalar.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,10 @@ test "scalar25519" {
771771
var y = x.toBytes();
772772
try rejectNonCanonical(y);
773773
var buf: [128]u8 = undefined;
774-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{y}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
774+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&y)}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
775775

776776
const reduced = reduce(field_size);
777-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{reduced}), "0000000000000000000000000000000000000000000000000000000000000000");
777+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&reduced)}), "0000000000000000000000000000000000000000000000000000000000000000");
778778
}
779779

780780
test "non-canonical scalar25519" {
@@ -788,5 +788,5 @@ test "mulAdd overflow check" {
788788
const c: [32]u8 = [_]u8{0xff} ** 32;
789789
const x = mulAdd(a, b, c);
790790
var buf: [128]u8 = undefined;
791-
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
791+
std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&x)}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
792792
}

lib/std/crypto/chacha20.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ test "crypto.xchacha20" {
876876
var ciphertext: [input.len]u8 = undefined;
877877
XChaCha20IETF.xor(ciphertext[0..], input[0..], 0, key, nonce);
878878
var buf: [2 * ciphertext.len]u8 = undefined;
879-
testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{ciphertext}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
879+
testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ciphertext)}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
880880
}
881881
{
882882
const data = "Additional data";
@@ -885,7 +885,7 @@ test "crypto.xchacha20" {
885885
var out: [input.len]u8 = undefined;
886886
try xchacha20poly1305Open(out[0..], ciphertext[0..], data, key, nonce);
887887
var buf: [2 * ciphertext.len]u8 = undefined;
888-
testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{ciphertext}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
888+
testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{s}", .{std.fmt.fmtSliceHexUpper(&ciphertext)}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
889889
testing.expectEqualSlices(u8, out[0..], input);
890890
ciphertext[0] += 1;
891891
testing.expectError(error.AuthenticationFailed, xchacha20poly1305Open(out[0..], ciphertext[0..], data, key, nonce));

lib/std/fmt.zig

Lines changed: 104 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,87 @@ fn formatFloatValue(
710710
return formatBuf(buf_stream.getWritten(), options, writer);
711711
}
712712

713+
fn formatSliceHexImpl(comptime uppercase: bool) type {
714+
const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
715+
716+
return struct {
717+
pub fn f(
718+
bytes: []const u8,
719+
comptime fmt: []const u8,
720+
options: std.fmt.FormatOptions,
721+
writer: anytype,
722+
) !void {
723+
var buf: [2]u8 = undefined;
724+
725+
for (bytes) |c| {
726+
buf[0] = charset[c >> 4];
727+
buf[1] = charset[c & 15];
728+
try writer.writeAll(&buf);
729+
}
730+
}
731+
};
732+
}
733+
734+
const formatSliceHexLower = formatSliceHexImpl(false).f;
735+
const formatSliceHexUpper = formatSliceHexImpl(true).f;
736+
737+
/// Return a Formatter for a []const u8 where every byte is formatted as a pair
738+
/// of lowercase hexadecimal digits.
739+
pub fn fmtSliceHexLower(bytes: []const u8) std.fmt.Formatter(formatSliceHexLower) {
740+
return .{ .data = bytes };
741+
}
742+
743+
/// Return a Formatter for a []const u8 where every byte is formatted as a pair
744+
/// of uppercase hexadecimal digits.
745+
pub fn fmtSliceHexUpper(bytes: []const u8) std.fmt.Formatter(formatSliceHexUpper) {
746+
return .{ .data = bytes };
747+
}
748+
749+
fn formatSliceEscapeImpl(comptime uppercase: bool) type {
750+
const charset = "0123456789" ++ if (uppercase) "ABCDEF" else "abcdef";
751+
752+
return struct {
753+
pub fn f(
754+
bytes: []const u8,
755+
comptime fmt: []const u8,
756+
options: std.fmt.FormatOptions,
757+
writer: anytype,
758+
) !void {
759+
var buf: [4]u8 = undefined;
760+
761+
buf[0] = '\\';
762+
buf[1] = 'x';
763+
764+
for (bytes) |c| {
765+
if (std.ascii.isPrint(c)) {
766+
try writer.writeByte(c);
767+
} else {
768+
buf[2] = charset[c >> 4];
769+
buf[3] = charset[c & 15];
770+
try writer.writeAll(&buf);
771+
}
772+
}
773+
}
774+
};
775+
}
776+
777+
const formatSliceEscapeLower = formatSliceEscapeImpl(false).f;
778+
const formatSliceEscapeUpper = formatSliceEscapeImpl(true).f;
779+
780+
/// Return a Formatter for a []const u8 where every non-printable ASCII
781+
/// character is escaped as \xNN, where NN is the character in lowercase
782+
/// hexadecimal notation.
783+
pub fn fmtSliceEscapeLower(bytes: []const u8) std.fmt.Formatter(formatSliceEscapeLower) {
784+
return .{ .data = bytes };
785+
}
786+
787+
/// Return a Formatter for a []const u8 where every non-printable ASCII
788+
/// character is escaped as \xNN, where NN is the character in uppercase
789+
/// hexadecimal notation.
790+
pub fn fmtSliceEscapeUpper(bytes: []const u8) std.fmt.Formatter(formatSliceEscapeUpper) {
791+
return .{ .data = bytes };
792+
}
793+
713794
pub fn formatText(
714795
bytes: []const u8,
715796
comptime fmt: []const u8,
@@ -718,21 +799,18 @@ pub fn formatText(
718799
) !void {
719800
if (comptime std.mem.eql(u8, fmt, "s")) {
720801
return formatBuf(bytes, options, writer);
721-
} else if (comptime (std.mem.eql(u8, fmt, "x") or std.mem.eql(u8, fmt, "X"))) {
722-
for (bytes) |c| {
723-
try formatInt(c, 16, fmt[0] == 'X', FormatOptions{ .width = 2, .fill = '0' }, writer);
724-
}
725-
return;
726-
} else if (comptime (std.mem.eql(u8, fmt, "e") or std.mem.eql(u8, fmt, "E"))) {
727-
for (bytes) |c| {
728-
if (std.ascii.isPrint(c)) {
729-
try writer.writeByte(c);
730-
} else {
731-
try writer.writeAll("\\x");
732-
try formatInt(c, 16, fmt[0] == 'E', FormatOptions{ .width = 2, .fill = '0' }, writer);
733-
}
734-
}
735-
return;
802+
} else if (comptime (std.mem.eql(u8, fmt, "x"))) {
803+
@compileError("specifier 'x' has been deprecated, wrap your argument in std.fmt.fmtSliceHexLower instead");
804+
} else if (comptime (std.mem.eql(u8, fmt, "X"))) {
805+
@compileError("specifier 'X' has been deprecated, wrap your argument in std.fmt.fmtSliceHexUpper instead");
806+
} else if (comptime (std.mem.eql(u8, fmt, "e"))) {
807+
@compileError("specifier 'e' has been deprecated, wrap your argument in std.fmt.fmtSliceEscapeLower instead");
808+
} else if (comptime (std.mem.eql(u8, fmt, "E"))) {
809+
@compileError("specifier 'X' has been deprecated, wrap your argument in std.fmt.fmtSliceEscapeUpper instead");
810+
} else if (comptime std.mem.eql(u8, fmt, "z")) {
811+
@compileError("specifier 'z' has been deprecated, wrap your argument in std.zig.fmtId instead");
812+
} else if (comptime std.mem.eql(u8, fmt, "Z")) {
813+
@compileError("specifier 'Z' has been deprecated, wrap your argument in std.zig.fmtEscapes instead");
736814
} else {
737815
@compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
738816
}
@@ -1695,9 +1773,9 @@ test "slice" {
16951773
}
16961774

16971775
test "escape non-printable" {
1698-
try expectFmt("abc", "{e}", .{"abc"});
1699-
try expectFmt("ab\\xffc", "{e}", .{"ab\xffc"});
1700-
try expectFmt("ab\\xFFc", "{E}", .{"ab\xffc"});
1776+
try expectFmt("abc", "{s}", .{fmtSliceEscapeLower("abc")});
1777+
try expectFmt("ab\\xffc", "{s}", .{fmtSliceEscapeLower("ab\xffc")});
1778+
try expectFmt("ab\\xFFc", "{s}", .{fmtSliceEscapeUpper("ab\xffc")});
17011779
}
17021780

17031781
test "pointer" {
@@ -1970,13 +2048,13 @@ test "struct.zero-size" {
19702048

19712049
test "bytes.hex" {
19722050
const some_bytes = "\xCA\xFE\xBA\xBE";
1973-
try expectFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{some_bytes});
1974-
try expectFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{some_bytes});
2051+
try expectFmt("lowercase: cafebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(some_bytes)});
2052+
try expectFmt("uppercase: CAFEBABE\n", "uppercase: {X}\n", .{fmtSliceHexUpper(some_bytes)});
19752053
//Test Slices
1976-
try expectFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{some_bytes[0..2]});
1977-
try expectFmt("lowercase: babe\n", "lowercase: {x}\n", .{some_bytes[2..]});
2054+
try expectFmt("uppercase: CAFE\n", "uppercase: {X}\n", .{fmtSliceHexUpper(some_bytes[0..2])});
2055+
try expectFmt("lowercase: babe\n", "lowercase: {x}\n", .{fmtSliceHexLower(some_bytes[2..])});
19782056
const bytes_with_zeros = "\x00\x0E\xBA\xBE";
1979-
try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
2057+
try expectFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{fmtSliceHexLower(bytes_with_zeros)});
19802058
}
19812059

19822060
pub const trim = @compileError("deprecated; use std.mem.trim with std.ascii.spaces instead");
@@ -2004,9 +2082,9 @@ pub fn hexToBytes(out: []u8, input: []const u8) ![]u8 {
20042082

20052083
test "hexToBytes" {
20062084
var buf: [32]u8 = undefined;
2007-
try expectFmt("90" ** 32, "{X}", .{try hexToBytes(&buf, "90" ** 32)});
2008-
try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")});
2009-
try expectFmt("", "{X}", .{try hexToBytes(&buf, "")});
2085+
try expectFmt("90" ** 32, "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "90" ** 32))});
2086+
try expectFmt("ABCD", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, "ABCD"))});
2087+
try expectFmt("", "{s}", .{fmtSliceHexUpper(try hexToBytes(&buf, ""))});
20102088
std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z"));
20112089
std.testing.expectError(error.InvalidLength, hexToBytes(&buf, "AAA"));
20122090
std.testing.expectError(error.NoSpaceLeft, hexToBytes(buf[0..1], "ABAB"));

src/Cache.zig

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ pub const HashHelper = struct {
153153
hh.hasher.final(&bin_digest);
154154

155155
var out_digest: [hex_digest_len]u8 = undefined;
156-
_ = std.fmt.bufPrint(&out_digest, "{x}", .{bin_digest}) catch unreachable;
156+
_ = std.fmt.bufPrint(
157+
&out_digest,
158+
"{s}",
159+
.{std.fmt.fmtSliceHexLower(&bin_digest)},
160+
) catch unreachable;
157161
return out_digest;
158162
}
159163
};
@@ -250,7 +254,11 @@ pub const Manifest = struct {
250254
var bin_digest: BinDigest = undefined;
251255
self.hash.hasher.final(&bin_digest);
252256

253-
_ = std.fmt.bufPrint(&self.hex_digest, "{x}", .{bin_digest}) catch unreachable;
257+
_ = std.fmt.bufPrint(
258+
&self.hex_digest,
259+
"{s}",
260+
.{std.fmt.fmtSliceHexLower(&bin_digest)},
261+
) catch unreachable;
254262

255263
self.hash.hasher = hasher_init;
256264
self.hash.hasher.update(&bin_digest);
@@ -549,7 +557,11 @@ pub const Manifest = struct {
549557
self.hash.hasher.final(&bin_digest);
550558

551559
var out_digest: [hex_digest_len]u8 = undefined;
552-
_ = std.fmt.bufPrint(&out_digest, "{x}", .{bin_digest}) catch unreachable;
560+
_ = std.fmt.bufPrint(
561+
&out_digest,
562+
"{s}",
563+
.{std.fmt.fmtSliceHexLower(&bin_digest)},
564+
) catch unreachable;
553565

554566
return out_digest;
555567
}
@@ -565,7 +577,11 @@ pub const Manifest = struct {
565577
var encoded_digest: [hex_digest_len]u8 = undefined;
566578

567579
for (self.files.items) |file| {
568-
_ = std.fmt.bufPrint(&encoded_digest, "{x}", .{file.bin_digest}) catch unreachable;
580+
_ = std.fmt.bufPrint(
581+
&encoded_digest,
582+
"{s}",
583+
.{std.fmt.fmtSliceHexLower(&file.bin_digest)},
584+
) catch unreachable;
569585
try writer.print("{d} {d} {d} {s} {s}\n", .{
570586
file.stat.size,
571587
file.stat.inode,

src/translate_c.zig

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6105,7 +6105,12 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!*
61056105
};
61066106
return &node.base;
61076107
} else {
6108-
const token = try appendTokenFmt(c, .IntegerLiteral, "0x{x}", .{slice[1 .. slice.len - 1]});
6108+
const token = try appendTokenFmt(
6109+
c,
6110+
.IntegerLiteral,
6111+
"0x{s}",
6112+
.{std.fmt.fmtSliceHexLower(slice[1 .. slice.len - 1])},
6113+
);
61096114
const node = try c.arena.create(ast.Node.OneToken);
61106115
node.* = .{
61116116
.base = .{ .tag = .IntegerLiteral },

0 commit comments

Comments
 (0)