From: Rico Tzschichholz Date: Tue, 1 Aug 2023 09:59:52 +0000 (+0200) Subject: vala: Correctly handle possible null from SourceFile.get_source_line() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69e59d15b6909b5689ab3f81844898bf77d2c42f;p=thirdparty%2Fvala.git vala: Correctly handle possible null from SourceFile.get_source_line() Fixes https://gitlab.gnome.org/GNOME/vala/issues/1464 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 41f293c1f..54456253a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1041,6 +1041,7 @@ TESTS = \ parser/statement-keyword-as-identifier.vala \ parser/statement-outside-root.test \ parser/switch-statement.vala \ + parser/switch-section-missing-colon.test \ parser/switch-section-outside-switch.test \ parser/template.vala \ parser/try-catch-in-switch-case-invalid.test \ diff --git a/tests/parser/switch-section-missing-colon.test b/tests/parser/switch-section-missing-colon.test new file mode 100644 index 000000000..923065d07 --- /dev/null +++ b/tests/parser/switch-section-missing-colon.test @@ -0,0 +1,9 @@ +Invalid Code + +void main () { + int foo = 0; + switch (foo) { + case 0 + break; + } +} diff --git a/vala/valareport.vala b/vala/valareport.vala index 081f37c42..5e4885a6e 100644 --- a/vala/valareport.vala +++ b/vala/valareport.vala @@ -233,7 +233,10 @@ public class Vala.Report { */ private void report_source (SourceReference source) { for (int idx = source.begin.line; idx <= source.end.line; idx++) { - string offending_line = source.file.get_source_line (idx); + string? offending_line = source.file.get_source_line (idx); + if (offending_line == null) { + break; + } printerr ("%5d | %s\n", idx, offending_line); printerr (" | "); stderr.puts (caret_color_start);