OpenBCI/OpenBCI_Cyton_Library

Undefined Behaviour at OpenBCI_32bit_Library.cpp:2177

edrose opened this issue · 0 comments

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.