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

Use of realloc may cause data corruption #1

Closed
cversek opened this issue Aug 28, 2013 · 2 comments
Closed

Use of realloc may cause data corruption #1

cversek opened this issue Aug 28, 2013 · 2 comments
Labels

Comments

@cversek
Copy link
Member

cversek commented Aug 28, 2013

I've been tracing a problem with the command strings frequently being corrupted after using addCommand several times. I believe that the following line in SerialCommand.cpp is a bug:

   commandList = (SerialCommandCallback *) realloc(commandList, (commandCount + 1) * sizeof(SerialCommandCallback));

The C++ reference on realloc states the following:

The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate.

A simple but inelegant fix would be to hard-code the size of commandList in the header file and limit the maximum number of commands.

@cversek
Copy link
Member Author

cversek commented Aug 28, 2013

Note: this is a clone of this issue in the parent repo. This fork was created to fix this serious bug.

@cversek
Copy link
Member Author

cversek commented Sep 1, 2013

This was a false alarm: realloc was not being used incorrectly. Apparently, the data corruption was coming from another source, that being the lack of sufficient RAM.

@cversek cversek closed this as completed Sep 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant