diff options
| author | bobsayshilol <bobsayshilol@live.co.uk> | 2024-10-27 18:11:46 +0000 |
|---|---|---|
| committer | bobsayshilol <bobsayshilol@live.co.uk> | 2024-10-27 21:24:36 +0000 |
| commit | 771d308d643f9e3d59b2451fe18c5bdd845aba1e (patch) | |
| tree | 115c31feb13d9cc3f0e00c4f16f340f198b46994 /src/llvm_backend_expr.cpp | |
| parent | 1f187adff455a8de499b73e1ccf9210bd8f830c9 (diff) | |
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|.
Diffstat (limited to 'src/llvm_backend_expr.cpp')
| -rw-r--r-- | src/llvm_backend_expr.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index de7cadaf3..b5f6437a4 100644 --- a/src/llvm_backend_expr.cpp +++ b/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); return lb_addr_load(p, res); } 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); lbValue res = {}; res.type = t; |