mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 00:24:12 +00:00
[qfcc] Ensure multi-vector objects have the correct type
Failing to promote ints to the algebra type results in a segfault in assignment of a multi-vector due to the symbol pointer walking off the end of the list of symbols.
This commit is contained in:
parent
2b5b55f416
commit
8dd0410968
1 changed files with 18 additions and 15 deletions
|
@ -189,11 +189,29 @@ check_types (expr_t **e, algebra_t *algebra)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static expr_t *
|
||||||
|
promote_scalar (type_t *dst_type, expr_t *scalar)
|
||||||
|
{
|
||||||
|
auto scalar_type = get_type (scalar);
|
||||||
|
if (scalar_type != dst_type) {
|
||||||
|
if (!type_promotes (dst_type, scalar_type)) {
|
||||||
|
warning (scalar, "demoting %s to %s (use a cast)",
|
||||||
|
get_type_string (scalar_type),
|
||||||
|
get_type_string (dst_type));
|
||||||
|
}
|
||||||
|
scalar = cast_expr (dst_type, scalar);
|
||||||
|
}
|
||||||
|
return scalar;
|
||||||
|
}
|
||||||
|
|
||||||
static expr_t *
|
static expr_t *
|
||||||
mvec_expr (expr_t *expr, algebra_t *algebra)
|
mvec_expr (expr_t *expr, algebra_t *algebra)
|
||||||
{
|
{
|
||||||
auto mvtype = get_type (expr);
|
auto mvtype = get_type (expr);
|
||||||
if (expr->type == ex_multivec || is_scalar (mvtype)) {
|
if (expr->type == ex_multivec || is_scalar (mvtype)) {
|
||||||
|
if (!is_algebra (mvtype)) {
|
||||||
|
expr = promote_scalar (algebra->type, expr);
|
||||||
|
}
|
||||||
return expr;
|
return expr;
|
||||||
}
|
}
|
||||||
if (!is_algebra (mvtype)) {
|
if (!is_algebra (mvtype)) {
|
||||||
|
@ -303,21 +321,6 @@ mvec_gather (expr_t **components, algebra_t *algebra)
|
||||||
return mvec;
|
return mvec;
|
||||||
}
|
}
|
||||||
|
|
||||||
static expr_t *
|
|
||||||
promote_scalar (type_t *dst_type, expr_t *scalar)
|
|
||||||
{
|
|
||||||
auto scalar_type = get_type (scalar);
|
|
||||||
if (scalar_type != dst_type) {
|
|
||||||
if (!type_promotes (dst_type, scalar_type)) {
|
|
||||||
warning (scalar, "demoting %s to %s (use a cast)",
|
|
||||||
get_type_string (scalar_type),
|
|
||||||
get_type_string (dst_type));
|
|
||||||
}
|
|
||||||
scalar = cast_expr (dst_type, scalar);
|
|
||||||
}
|
|
||||||
return scalar;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool __attribute__((const))
|
static bool __attribute__((const))
|
||||||
ext_compat (const expr_t *a, const expr_t *b)
|
ext_compat (const expr_t *a, const expr_t *b)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue