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

For Issue 726, Semihost SYS_READ returns incorrect value on EOF #727

Merged
merged 1 commit into from
Jul 26, 2018

Conversation

donmr
Copy link
Contributor

@donmr donmr commented Jul 26, 2018

Use local variable for read_result instead of *ret, and fix calculation of *ret for EOF case.

@xor-gate
Copy link
Member

Great, looks like a good fix! Thanks for your PR.

@xor-gate xor-gate added this to the Next milestone Jul 26, 2018
@xor-gate xor-gate merged commit ca6ecc4 into stlink-org:master Jul 26, 2018
src/gdbserver/semihosting.c Show resolved Hide resolved
src/gdbserver/semihosting.c Show resolved Hide resolved
src/gdbserver/semihosting.c Show resolved Hide resolved
@donmr
Copy link
Contributor Author

donmr commented Jul 27, 2018

I agree with Fabien-Chouteau's review items. Thanks for catching my sloppy errors.

I'll submit another PR shortly (after I check it myself one more time).

xor-gate pushed a commit that referenced this pull request Jul 28, 2018
* Use local variable for read_result instead of *ret, and fix
calculation of *ret for EOF case.

* Found a problem when reading an odd (%4) number of bytes at the end
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.

* Fix Issues from Fabien-Chouteau's review of my previous patch in isue #727.

* Revert change to mem_write() so it does not confuse fixes to do_semihosting().

* Add cast to avoid warning.
donmr added a commit to donmr/stlink that referenced this pull request Jul 28, 2018
Fixes to SYS_READ changes in PR stlink-org#727 per review. (stlink-org#729)
donmr added a commit to donmr/stlink that referenced this pull request Jul 28, 2018
Fixes to SYS_READ changes in PR stlink-org#727 per review. (stlink-org#729)
xor-gate pushed a commit that referenced this pull request Aug 1, 2018
* Use local variable for read_result instead of *ret, and fix
calculation of *ret for EOF case.

* Found a problem when reading an odd (%4) number of bytes at the end
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.

* Fix Issues from Fabien-Chouteau's review of my previous patch in isue #727.

* Revert change to mem_write() so it does not confuse fixes to do_semihosting().

* Add cast to avoid warning.

* Restore change to mem_write to return immeadiately if len == 0.
Add more comments on further possible issues and ways to handle them.
Using a branch to separate this change from others as it may need
more discussion and go on for a while...

* Remove cast of "-1" to uint32_t.  It's now compared to a ssize_t
and the compiler should be fine with that without any cast.
@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
4 participants