harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f97053046bf969b5ac60e5802ec7106e52fa2cbb
parent a7fb6028b0234691d400749ffe5fa154d5b1635b
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Wed, 12 Jan 2022 00:52:31 +0100

don't SIGFPE on tuples with zero-sized values

Fixes: https://todo.sr.ht/~sircmpwn/hare/546
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>

Diffstat:
Minclude/type_store.h | 3++-
Msrc/check.c | 3++-
Msrc/type_store.c | 8+++++++-
3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/include/type_store.h b/include/type_store.h @@ -1,6 +1,7 @@ #ifndef HARE_TYPESTORE_H #define HARE_TYPESTORE_H #include "ast.h" +#include "lex.h" #include "types.h" #define TYPE_STORE_BUCKETS 65536 @@ -55,6 +56,6 @@ const struct type *type_store_tagged_to_union( struct type_store *store, const struct type *tagged); const struct type *type_store_lookup_tuple(struct type_store *store, - struct type_tuple *values); + struct type_tuple *values, struct location loc); #endif diff --git a/src/check.c b/src/check.c @@ -2645,7 +2645,8 @@ check_expr_tuple(struct context *ctx, return; } } else { - expr->result = type_store_lookup_tuple(ctx->store, &result); + expr->result = type_store_lookup_tuple(ctx->store, &result, + aexpr->loc); } ttuple = &type_dealias(expr->result)->tuple; diff --git a/src/type_store.c b/src/type_store.c @@ -1072,7 +1072,8 @@ type_store_tagged_to_union(struct type_store *store, const struct type *tagged) } const struct type * -type_store_lookup_tuple(struct type_store *store, struct type_tuple *values) +type_store_lookup_tuple(struct type_store *store, struct type_tuple *values, + struct location loc) { struct type type = { .storage = STORAGE_TUPLE, @@ -1082,6 +1083,11 @@ type_store_lookup_tuple(struct type_store *store, struct type_tuple *values) if (t->type->align > type.align) { type.align = t->type->align; } + if (t->type->size == 0 || t->type->align == 0) { + error(store->check_context, loc, + "Tuple values must have nonzero size and alignment"); + break; + } t->offset = type.size % t->type->align + type.size; type.size += type.size % t->type->align + t->type->size; }