diff --git a/src/translate_c.zig b/src/translate_c.zig index fa23b861e3..41b87ade21 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -5647,7 +5647,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node { switch (m.list[m.i].id) { .IntegerLiteral => |suffix| { var radix: []const u8 = "decimal"; - if (lit_bytes.len > 2 and lit_bytes[0] == '0') { + if (lit_bytes.len >= 2 and lit_bytes[0] == '0') { switch (lit_bytes[1]) { '0'...'7' => { // Octal diff --git a/test/translate_c.zig b/test/translate_c.zig index 540c560839..637d491f49 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -3842,4 +3842,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub const FOO = ""; }); + + cases.add("leading zeroes", + \\#define O_RDONLY 00 + \\#define HELLO 000 + \\#define ZERO 0 + \\#define WORLD 00000123 + , &[_][]const u8{ + \\pub const O_RDONLY = @as(c_int, 0o0); + \\pub const HELLO = @as(c_int, 0o00); + \\pub const ZERO = @as(c_int, 0); + \\pub const WORLD = @as(c_int, 0o0000123); + }); }