Browse Source

Fix invalid union access

UBSan spotted that |src->Basic.kind| had a value outside the range of
|BasicKind| due to it actually being a |Type_Pointer|. Since these are
stored in a union there could be cases where the value of |kind| just
so happens to be |Basic_string|, in which case the branch would have
been taken when it shouldn't have been.

To fix this simply check that it's a |Type_Basic| before treating it as
a |Basic|.
bobsayshilol 9 months ago
parent
commit
771d308d64
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/llvm_backend_expr.cpp

+ 1 - 1
src/llvm_backend_expr.cpp

@@ -1647,7 +1647,7 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
 			lb_emit_store(p, a1, id);
 			lb_emit_store(p, a1, id);
 			return lb_addr_load(p, res);
 			return lb_addr_load(p, res);
 		} else if (dst->kind == Type_Basic) {
 		} else if (dst->kind == Type_Basic) {
-			if (src->Basic.kind == Basic_string && dst->Basic.kind == Basic_cstring) {
+			if (src->kind == Type_Basic && src->Basic.kind == Basic_string && dst->Basic.kind == Basic_cstring) {
 				String str = lb_get_const_string(m, value);
 				String str = lb_get_const_string(m, value);
 				lbValue res = {};
 				lbValue res = {};
 				res.type = t;
 				res.type = t;