OpenBCI / OpenBCI_Cyton_Library

Repository for OpenBCI Cyton Arduino Libraries
MIT License
87 stars 88 forks source link

Undefined Behaviour at OpenBCI_32bit_Library.cpp:2177 #103

Open edrose opened 1 year ago

edrose commented 1 year ago

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.