Concatenating an const empty slice with another array caused a null pointer access.

This commit is contained in:
Christoffer Lerno
2025-01-18 23:50:31 +01:00
parent c3f5806aa3
commit 5de03abe0d
3 changed files with 9 additions and 0 deletions

View File

@@ -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.

View File

@@ -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);

View File

@@ -0,0 +1,6 @@
fn int main()
{
char[] $res;
$res = { '0' } +++ $res;
return 0;
}