diff --git a/releasenotes.md b/releasenotes.md index daf5fb028..ff10e05c9 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,7 @@ - Compiler allows a generic module to be declared with different parameters #1856. - Fix issue with `@const` where the statement `$foo = 1;` was not considered constant. - Const strings and bytes were not properly converted to compile time bools. +- Concatenating an const empty slice with another array caused a null pointer access. ### Stdlib changes - Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter. diff --git a/src/compiler/sema_const.c b/src/compiler/sema_const.c index 4a455b402..fdd3c0347 100644 --- a/src/compiler/sema_const.c +++ b/src/compiler/sema_const.c @@ -417,6 +417,8 @@ bool sema_expr_analyse_ct_concat(SemaContext *context, Expr *concat_expr, Expr * continue; } ConstInitializer *init = expr_const_initializer_from_expr(single_expr); + // Skip zero arrays from slices. + if (!init) continue; if (init && init->kind != CONST_INIT_ARRAY_FULL) { ASSERT0(!init || init->type != type_untypedlist); diff --git a/test/test_suite/compile_time/concat_zero_slice.c3t b/test/test_suite/compile_time/concat_zero_slice.c3t new file mode 100644 index 000000000..aed583c0a --- /dev/null +++ b/test/test_suite/compile_time/concat_zero_slice.c3t @@ -0,0 +1,6 @@ +fn int main() +{ + char[] $res; + $res = { '0' } +++ $res; + return 0; +} \ No newline at end of file