aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md2
-rw-r--r--src/types.c15
2 files changed, 17 insertions, 0 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 293ff431..b16a4e8c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -57,6 +57,8 @@
- Optional paths no longer fail to compile when you check them for `none`.
- Text replacement no longer infinitely loops when given an empty text to replace.
- Short CLI flag aliases now no longer use the first letter of the argument.
+ - Stack memory was not correctly detected in some cases, leading to potential
+ memory errors.
## v0.3
diff --git a/src/types.c b/src/types.c
index 33c5e55b..73c02807 100644
--- a/src/types.c
+++ b/src/types.c
@@ -249,6 +249,21 @@ PUREFUNC bool has_stack_memory(type_t *t) {
switch (t->tag) {
case PointerType: return Match(t, PointerType)->is_stack;
case OptionalType: return has_stack_memory(Match(t, OptionalType)->type);
+ case ListType: return has_stack_memory(Match(t, ListType)->item_type);
+ case TableType:
+ return has_stack_memory(Match(t, TableType)->key_type) || has_stack_memory(Match(t, TableType)->value_type);
+ case StructType: {
+ for (arg_t *field = Match(t, StructType)->fields; field; field = field->next) {
+ if (has_stack_memory(field->type)) return true;
+ }
+ return false;
+ }
+ case EnumType: {
+ for (tag_t *tag = Match(t, EnumType)->tags; tag; tag = tag->next) {
+ if (tag->type && has_stack_memory(tag->type)) return true;
+ }
+ return false;
+ }
default: return false;
}
}