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

Undefined Behaviour at OpenBCI_32bit_Library.cpp:2177 #103

Open
edrose opened this issue May 6, 2023 · 0 comments
Open

Undefined Behaviour at OpenBCI_32bit_Library.cpp:2177 #103

edrose opened this issue May 6, 2023 · 0 comments

Comments

@edrose
Copy link

edrose commented May 6, 2023

In the function uint8_t *OpenBCI_32bit_Library::getGains(void) it creates an array on the stack and then returns a pointer to that array.

After the function returns, the array that it points to is then in unused stack space which will be overwritten the moment another function is called.

I haven't got a WiFi shield to test it with, however I cannot see how this code can work. The result of the function is immediately passed into another function, so the stack frame where the variable used to reside will be overwritten before it's ever used.

The gains variable should be declared static on line 2179 to prevent it from going out of scope when the function returns.

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

No branches or pull requests

1 participant