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

be quicker about determining erased byte pattern when flashing #377

Merged
merged 1 commit into from
Feb 27, 2016

Conversation

gtalusan
Copy link
Contributor

Not a bug, just a slight improvement.

@texane
Copy link
Collaborator

texane commented Feb 27, 2016

Did you test it ? index is an unsigned int, always >= 0 ... so the terminal condition of the for loop looks suspicious to me ... ?

@gtalusan
Copy link
Contributor Author

Yup. It behaves the same as previously but with less iterations. The index is decrementing so it'll always hit 0 or break out if the byte being inspected isn't erased_pattern.

If the break condition were just true since index is an unsigned, then we'd get wrap around and an input that was full of 0xff or whatever erased_pattern is, would cause an infinite loop.

@texane
Copy link
Collaborator

texane commented Feb 27, 2016

I understand what it does. But when index hits 0, the for loop does not exit, so
index will wrap to (unsigned int)-1 = 0xffffffff, and invalid memory reference may
occur. That is what is not correct, not the goal itself.

ps: thanks for your commits by the way !

@gtalusan
Copy link
Contributor Author

Ah, I see!

Okay, updated. Here I tested with a bin full of 0xff's and made st_write_flash go through the step of erasing the flash if mf.len == num_empty. Previously the code would do nothing.

The unsigned confusion should be gone too - the precondition is now to check if we've seen as many empty bytes as there are bytes mapped in memory.

There's a bit of pollution of st_write_flash's function declaration, but that's because the function does a bit much.

texane added a commit that referenced this pull request Feb 27, 2016
be quicker about determining erased byte pattern when flashing
@texane texane merged commit 44375c9 into stlink-org:master Feb 27, 2016
@texane
Copy link
Collaborator

texane commented Feb 27, 2016

Thanks. I rewrite the code a little bit, hope you do not mind.

@gtalusan
Copy link
Contributor Author

Thanks!

On Feb 27, 2016, at 1:18 PM, texane notifications@github.com wrote:

Thanks. I rewrite the code a little bit, hope you do not mind.


Reply to this email directly or view it on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong contents written for particular binary file
3 participants