Skip to content

Commit

Permalink
Concatenating an const empty slice with another array caused a null p…
Browse files Browse the repository at this point in the history
…ointer access.
  • Loading branch information
lerno committed Jan 18, 2025
1 parent c3f5806 commit 5de03ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/sema_const.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/test_suite/compile_time/concat_zero_slice.c3t
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn int main()
{
char[] $res;
$res = { '0' } +++ $res;
return 0;
}

0 comments on commit 5de03ab

Please sign in to comment.