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

Further fix for read at EOF, don't write if length is zero. #728

Closed
wants to merge 4 commits into from

Conversation

donmr
Copy link
Contributor

@donmr donmr commented Jul 26, 2018

I found a further problem when reading at the end of a file.

If there is some data in the file, but not enough, then after the first read call returns some data, fread will ask for the rest with an updated pointer. If the first read returned an odd modulo 4 number of bytes, then this second read call will happen with a pointer that is not 32 bit aligned.

In do_semihosting, the second read gets 0 bytes but still calls mem_write. The code in mem_write which forces an aligned address then writes more data than it should altering the values returned from the first read call.

This change simply has mem_write return without doing anything if the length is zero.

donmr added 3 commits July 26, 2018 09:02
of a file.  fread (on stm32) get them (say 3 bytes), then askes for
more.  do_semihosting gets a read return of 0 and tries to write that.
mem_write alters the address to be aligned and overwrites then 3 bytes
from the last read.

This change simply tells mem_write to do nothing if len is 0.
@donmr
Copy link
Contributor Author

donmr commented Jul 26, 2018

Opps, the git push didn't get in (I tried to use ssh). It's there now. Is this PR sufficent or do I need to create another??

@donmr
Copy link
Contributor Author

donmr commented Jul 27, 2018

I'm going to close this PR, and revert the change so I can get the fixes based on the previous review in by themselves. Then I'll re-submit this one.

@donmr donmr closed this Jul 27, 2018
@Nightwalker-87 Nightwalker-87 added this to the v1.5.1 milestone Mar 18, 2020
@Nightwalker-87 Nightwalker-87 linked an issue Mar 18, 2020 that may be closed by this pull request
6 tasks
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 23, 2020
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.

Semihosting SYS_READ returns incorrect value on EOF
2 participants