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

realloc doesn't preserve content #15

Closed
matrefeytontias opened this issue Nov 15, 2014 · 6 comments
Closed

realloc doesn't preserve content #15

matrefeytontias opened this issue Nov 15, 2014 · 6 comments

Comments

@matrefeytontias
Copy link

"void *realloc(void *ptr, size_t size);
...
The realloc() function changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged in the range from the start of the region up to the minimum of the old and new sizes."
Source: http://linux.die.net/man/3/realloc

@Vogtinator
Copy link
Contributor

It should do. Can you provide a test case?

@matrefeytontias
Copy link
Author

Mh, so I tried to make a very simple program that demonstrates this but for some reason I can't reproduce it with such program. I'll go with the program where I found this instead, but it's pretty big:

void log_ticks(runloop_state_t *state) {
    int i;
    for(i = 0; i < 40; i++)
        printf("Timer %d index %d\n", i, state->ticks[i].index);
    bkpt();
}
typedef struct
{
    int index;
    int after_cycle;
} timer_tick_t;

@Vogtinator
Copy link
Contributor

I believe I found the bug, it results in a 2 byte offset sometimes,
that's why legimet didn't notice it when testing.
It'll take a moment to solve.

@Vogtinator
Copy link
Contributor

Fixed at 1855adf.

@matrefeytontias
Copy link
Author

Yep, fixed.

@Vogtinator
Copy link
Contributor

Great that you found it. It could have been a source of unreasonable bugs...

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

2 participants