From 5fa820a4625739691e2d3d55e32e3654937e4b0f Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 21 Jan 2026 00:43:30 +0100 Subject: [PATCH] When a global const has invalid attributes, handling is incorrect, leading to a crash #2785. --- releasenotes.md | 1 + src/compiler/parse_global.c | 2 +- test/test_suite/constants/const_unfinished_parse.c3 | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/constants/const_unfinished_parse.c3 diff --git a/releasenotes.md b/releasenotes.md index 94c29a966..59e1b2f79 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -28,6 +28,7 @@ - Failed to reject void compile time variables, leading to crash. #2781 - Inferring the size of a slice with an inner inferred array using {} isn't detected as error #2783 - Bug in sysv abi when passing union in with floats #2784 +- When a global const has invalid attributes, handling is incorrect, leading to a crash #2785. ### Fixes - Regression with npot vector in struct triggering an assert #2219. diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 7113d2d9f..3de9a0ad8 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1007,7 +1007,7 @@ Decl *parse_const_declaration(ParseContext *c, bool is_global, bool is_extern) // Differentiate between global and local attributes, global have visibility if (is_global) { - if (!parse_attributes_for_global(c, decl)) return false; + if (!parse_attributes_for_global(c, decl)) return poisoned_decl; } else { diff --git a/test/test_suite/constants/const_unfinished_parse.c3 b/test/test_suite/constants/const_unfinished_parse.c3 new file mode 100644 index 000000000..07e929031 --- /dev/null +++ b/test/test_suite/constants/const_unfinished_parse.c3 @@ -0,0 +1 @@ +const A @if(; // #error: An expression was expected. \ No newline at end of file