Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix reading uninitialized variable right_red in map.c (#349) #362

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

henrybear327
Copy link
Collaborator

The struct member right_red is used in several functions, such as rb_node_set_right(). It has been reported by infer and LLVM static analyzer that right_red isn't initialized before being used.

By tracing the node initialization function calls (starting from map_create_node), it can be seen that rb_node_set_right is the function where right_red is attempted to be initialized, but we are indeed performing &1 on an uninitialized value.

In this commit, a change to using calloc guarantees the struct members will be zeroed out during allocation, which in terms serves as initialization.

The struct member right_red is used in several functions, such as 
rb_node_set_right(). It has been reported by infer and LLVM static 
analyzer that right_red isn't initialized before used.

By tracing the node initialization function calls (starting from 
map_create_node), it can be seen that rb_node_set_right is the function
where right_red is attempted to be initialized, but we are indeed 
performing &1 on an uninitialized value. 

In this commit, a change to using calloc guarantees the struct members 
will be zeroed out during allocation, which in terms serves as 
initialization.
@henrybear327 henrybear327 self-assigned this Feb 26, 2024
@henrybear327 henrybear327 requested a review from jserv February 26, 2024 09:37
@henrybear327
Copy link
Collaborator Author

In this commit, a change to using calloc guarantees the struct members will be zeroed out during allocation, which in terms serves as initialization.

@jserv I am not very certain if this is a good idea to fix this problem. Maybe explicitly setting the initial values of the member variables in the node structure is a better idea?

@jserv jserv merged commit fc3207e into sysprog21:master Feb 26, 2024
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants