Segfault when failing to cast subexpression to 'isz' in pointer subtraction #2305.

This commit is contained in:
Christoffer Lerno
2025-07-15 21:47:42 +02:00
parent bb6fcdfa6f
commit 3650b81970
3 changed files with 13 additions and 1 deletions

View File

@@ -52,6 +52,7 @@
- Resize bug when resizing memory down in ArenaAllocator, DynamicArenaAllocator, BackedArenaAllocator.
- Error message for missing arg incorrect for methods with zero args #2296.
- Fix stringify of $vaexpr #2301.
- Segfault when failing to cast subexpression to 'isz' in pointer subtraction #2305.
### Stdlib changes
- Improve contract for readline. #2280

View File

@@ -7352,7 +7352,7 @@ static bool sema_expr_analyse_sub(SemaContext *context, Expr *expr, Expr *left,
}
// 6. Convert to isz
if (!cast_implicit_binary(context, right, offset_type, failed_ref)) return true;
if (!cast_implicit_binary(context, right, offset_type, failed_ref)) return false;
if (left->expr_kind == EXPR_POINTER_OFFSET)
{

View File

@@ -0,0 +1,11 @@
fn int main()
{
int ctrl = 0;
char* op;
if (ctrl >= 32)
{
uint len = (ctrl >> 5) - 1;
char* ref = op - ((ctrl & 31) << 8) - 1; // #error: an explicit cast to 'isz'
}
return 0;
}