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

readBin() is not "type-length-safe" #38

Open
sigmaeo opened this issue Mar 20, 2018 · 2 comments
Open

readBin() is not "type-length-safe" #38

sigmaeo opened this issue Mar 20, 2018 · 2 comments

Comments

@sigmaeo
Copy link

sigmaeo commented Mar 20, 2018

If you use:
uint32_t ui32 = cm.readBinArg();
Then readBinArg() or readBin() will read 4 Bytes from the receiving buffer, ignoring the real length of what is sent and any seperator that may come earlier.
If you send (with ID=1):

1,ABCD;

(with A=0x41, B=0x42, C=0x43, D=0x44) you will get as expected:
0x44434241 = 1145258561.
But if you send:

1,A;

you don't get 0x41 = 65, instead you will get a random value with 0x41 as LSB, 0x00 after it and 2 more "random" bytes from memory.

And ArgOk is not updated.

This should be enhanced with a test if the length (that slpit_r() sees) is big enough, but for this some more changes are needed.

sigmaeo added a commit to sigmaeo/Arduino-CmdMessenger that referenced this issue Mar 20, 2018
sigmaeo added a commit to sigmaeo/Arduino-CmdMessenger that referenced this issue Mar 20, 2018
@sigmaeo
Copy link
Author

sigmaeo commented Mar 20, 2018

I fixed this issue by myself in my fork and so it is included in pull #37.

sigmaeo added a commit to sigmaeo/Arduino-CmdMessenger that referenced this issue Mar 20, 2018
@pauleffect90
Copy link

pauleffect90 commented Aug 7, 2019

If I try to send a string as a binary argument to the PC app, it works fine. The other way around, though, does not.

I have a void OnRecieve() on the arduino that echoes back the argument. I used it to test sending binary chars, ints, etc from the PC side. Everything works, except string. It just print a ClRf.

Im guesssing this was the issue. Thank you for your contribution.

MatthiasKunnen added a commit to MatthiasKunnen/Arduino-CmdMessenger that referenced this issue Aug 3, 2020
Changes applied from:
<https://github.com/sigmaeo/Arduino-CmdMessenger/tree/eb8e413f1313dbf5012ae6b751a6246b41a4e5ad>

- Fix startCommand was not initialized
  not a problem on arduino, but with C++-Builder on Windows
- Add missing unescape() are missing (issue thijse#39)
- Make readBin() safe for less received bytes (see issue thijse#38)
- Replace Serial.print() with comms->print()
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