Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling an unknown function with a struct does not invalidate reachable memory #222

Closed
jerhard opened this issue May 10, 2021 · 0 comments · Fixed by #223
Closed

Calling an unknown function with a struct does not invalidate reachable memory #222

jerhard opened this issue May 10, 2021 · 0 comments · Fixed by #223
Assignees
Labels

Comments

@jerhard
Copy link
Member

jerhard commented May 10, 2021

When a struct that contains pointers is passed to an unknown function, the memory reachable from these pointers is not invalidated/set to top. Whereas if we passed a pointer to the struct to the unknown function, the memory blocks reachable would be invalidated correctly.

typedef struct list {
int val;
struct list *next;
} list_t;
// void mutate_list(list_t n){
// list_t *next = n.next;
// next->val = 42;
// }
int main(){
list_t first;
list_t second;
first.next = &second;
first.val = 1;
second.next = NULL;
second.val = 2;
// When passing a struct to an unknown function, reachable memory should be invalidated
mutate_list(first);
assert(second.val == 2); //UNKNOWN!
// Passing a pointer to the struct here.
mutate_list2(&first);
assert(second.val == 2); //UNKNOWN!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant