From 088f4b503994feb7c5abe64b8956d827ef9ae36f Mon Sep 17 00:00:00 2001 From: Daniel Gavin Date: Wed, 28 Apr 2021 12:53:04 +0200 Subject: [PATCH] fix out of bounds with empty struct --- core/odin/printer/printer.odin | 7 ++++++- core/odin/printer/visit.odin | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/odin/printer/printer.odin b/core/odin/printer/printer.odin index e1d9f5b7d..63c0c5fc7 100644 --- a/core/odin/printer/printer.odin +++ b/core/odin/printer/printer.odin @@ -493,7 +493,8 @@ align_var_decls :: proc(p: ^Printer) { line.format_tokens[i].kind == .Union || line.format_tokens[i].kind == .Enum || line.format_tokens[i].kind == .Struct || - line.format_tokens[i].kind == .For { + line.format_tokens[i].kind == .For || + line.format_tokens[i].kind == .If { continue_flag = true; } @@ -772,6 +773,10 @@ align_struct :: proc(p: ^Printer, index: int) { format_tokens := make([]TokenAndLength, brace_token.parameter_count, context.temp_allocator); + if brace_token.parameter_count == 0 { + return; + } + for line, line_index in p.lines[brace_line + 1:] { length := 0; diff --git a/core/odin/printer/visit.odin b/core/odin/printer/visit.odin index a6b6759de..003bb8332 100644 --- a/core/odin/printer/visit.odin +++ b/core/odin/printer/visit.odin @@ -487,9 +487,7 @@ visit_exprs :: proc(p: ^Printer, list: []^ast.Expr, add_comma := false, trailing //Don't move the first expression, it looks bad if i != 0 && force_newline { newline_position(p, 1); - } - - else if i != 0 { + } else if i != 0 { move_line_limit(p, expr.pos, 1); }