authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-08-19 12:03:14+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-20 01:45:34+03:00
log39f43fea8d0f6aa1c69cb7c3209f57f5ce00b273
tree29955e3bab27927cc678af3f88bdc38572265a15
parentbe2bd5848a880765f4bc7e2363ef201a0930a04b

fix: fix off-by-one for leading zeroes


2 files changed, 13 insertions(+), 1 deletions(-)

src/translate_c.zig+1-1
......@@ -5647,7 +5647,7 @@ fn parseCNumLit(c: *Context, m: *MacroCtx) ParseError!Node {
56475647 switch (m.list[m.i].id) {
56485648 .IntegerLiteral => |suffix| {
56495649 var radix: []const u8 = "decimal";
5650 if (lit_bytes.len > 2 and lit_bytes[0] == '0') {
5650 if (lit_bytes.len >= 2 and lit_bytes[0] == '0') {
56515651 switch (lit_bytes[1]) {
56525652 '0'...'7' => {
56535653 // Octal
test/translate_c.zig+12
......@@ -3842,4 +3842,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
38423842 , &[_][]const u8{
38433843 \\pub const FOO = "";
38443844 });
3845
3846 cases.add("leading zeroes",
3847 \\#define O_RDONLY 00
3848 \\#define HELLO 000
3849 \\#define ZERO 0
3850 \\#define WORLD 00000123
3851 , &[_][]const u8{
3852 \\pub const O_RDONLY = @as(c_int, 0o0);
3853 \\pub const HELLO = @as(c_int, 0o00);
3854 \\pub const ZERO = @as(c_int, 0);
3855 \\pub const WORLD = @as(c_int, 0o0000123);
3856 });
38453857}