Skip to content

Undefined Behaviour at OpenBCI_32bit_Library.cpp:2177 #103

Description

@edrose

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions