Problems with listappend #27

Open
opened 2026-03-18 19:01:53 +11:00 by DiamondNether90 · 7 comments

Try running tests/list.grnd, but replace the start with

setlist &favWords "hello" "there" "general"
listappend &favWords "kenobi"

What I've found

  • This is only a problem with strings
  • appendToList is not the problem, as this program works fine
#include "src/types.h"
#include "src/interpreter.h"

int main() {
    List list;
    list.size = 0;
    list.values = malloc(0);
    appendToList(&list, (GroundValue){ .data.stringVal = "Hello" });
    appendToList(&list, (GroundValue){ .data.stringVal = "World" });
    appendToList(&list, (GroundValue){ .data.stringVal = "Earth" });
    printf("%s\n", list.values[1].data.stringVal);
}
Try running `tests/list.grnd`, but replace the start with ```py setlist &favWords "hello" "there" "general" listappend &favWords "kenobi" ``` ## What I've found - This is only a problem with strings - `appendToList` is **not** the problem, as this program works fine ```c #include "src/types.h" #include "src/interpreter.h" int main() { List list; list.size = 0; list.values = malloc(0); appendToList(&list, (GroundValue){ .data.stringVal = "Hello" }); appendToList(&list, (GroundValue){ .data.stringVal = "World" }); appendToList(&list, (GroundValue){ .data.stringVal = "Earth" }); printf("%s\n", list.values[1].data.stringVal); } ```
DiamondNether90 added spent time 1 hour 2026-03-18 21:13:46 +11:00
Author
Member

Wow this was a rabbit hole

I think I've found the cause though. When I run printf("%i\n", in->args.args[1].type), it prints 0 (corresponding to int), rather than 2 (corresponding to string).

Wow this was a rabbit hole I think I've found the cause though. When I run `printf("%i\n", in->args.args[1].type)`, it prints 0 (corresponding to int), rather than 2 (corresponding to string).
Author
Member

I'm a bozo, disregard the previous post

I'm a bozo, disregard the previous post
Author
Member

Adding the following before the break; in case LISTAPPEND: prints the proper list.

for (size_t i = 0; i < value->data.listVal.size; i++) {
    printf("%s ", value->data.listVal.values[i].data.stringVal);
}
printf("\n");
Adding the following before the `break;` in `case LISTAPPEND:` prints the proper list. ```c for (size_t i = 0; i < value->data.listVal.size; i++) { printf("%s ", value->data.listVal.values[i].data.stringVal); } printf("\n"); ```
Author
Member

My theory is that it is a problem with the closure implementation

My theory is that it is a problem with the closure implementation
DiamondNether90 added spent time 1 hour 2026-03-19 09:04:58 +11:00
Owner

Issue is a use-after-free (in copyGroundValue), not associated with the closure implementation. I've temporarily stopped freeGroundValue from freeing strings, and the issue seems to be fixed. It's a small leak for now. I'll investigate the issue further after exams

Issue is a use-after-free (in copyGroundValue), not associated with the closure implementation. I've temporarily stopped freeGroundValue from freeing strings, and the issue seems to be fixed. It's a small leak for now. I'll investigate the issue further after exams
Owner

My theory is that it is a problem with the closure implementation

Reproducing the example does not invoke the closure system, I don't understand how it can be a closure error

> My theory is that it is a problem with the closure implementation Reproducing the example does not invoke the closure system, I don't understand how it can be a closure error
Author
Member

My theory is that it is a problem with the closure implementation

Reproducing the example does not invoke the closure system, I don't understand how it can be a closure error

Just a guess, I hadn't yet checked when the bug first appeared

> > My theory is that it is a problem with the closure implementation > > Reproducing the example does not invoke the closure system, I don't understand how it can be a closure error Just a guess, I hadn't yet checked when the bug first appeared
Sign in to join this conversation.
2 Participants
Notifications
Total Time Spent: 2 hours
DiamondNether90
2 hours
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ground/ground#27