Browse Source

Prevent panic when `swizzle` called with < 2 indices

The requirement for at least 2 indices has been sourced from
`lb_addr_swizzle` in `llvm_backend_general.cpp`, where there is an
assert to ensure the swizzle_count is `1 < n <= 4`.
Feoramund 1 year ago
parent
commit
49f147cc86
1 changed files with 3 additions and 0 deletions
  1. 3 0
      src/check_builtin.cpp

+ 3 - 0
src/check_builtin.cpp

@@ -2419,6 +2419,9 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
 		if (arg_count > max_count) {
 		if (arg_count > max_count) {
 			error(call, "Too many 'swizzle' indices, %td > %td", arg_count, max_count);
 			error(call, "Too many 'swizzle' indices, %td > %td", arg_count, max_count);
 			return false;
 			return false;
+		} else if (arg_count < 2) {
+			error(call, "Not enough 'swizzle' indices, %td < 2", arg_count);
+			return false;
 		}
 		}
 
 
 		if (type->kind == Type_Array) {
 		if (type->kind == Type_Array) {