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

bugfix: initializing allocated memory for ISR functions #23

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

pintarj
Copy link

@pintarj pintarj commented Apr 9, 2024

Allocating dynamic memory for ISR functions using malloc() leaves that memory uninitialized. This causes latter code to perform conditional jumps on uninitialized values. This causes that a GPIO can be randomly marked as already used (which happens in my case).

Output produced while debugging with valgrind:

Conditional jump or move depends on uninitialised value(s)
    at 0x48A8C74: gpioSetISRFunc (orin.c:2044)
    ...

The code that does the conditional jump on an uninitialized value:

if (ISRFunc_CFG[gpio]->gpio != 0) {
    // ...
}

The proposed solution simply uses calloc() instead of malloc(). This causes all the allocated memory to be initialized to 0.

Copy link
Owner

@Rubberazer Rubberazer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted and well done, funny how I overlooked this one despite all the testing and stuff. Anyways, many thanks for that and approving your request

@Rubberazer Rubberazer merged commit b0629f2 into Rubberazer:main Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants