thijse / Arduino-CmdMessenger

CmdMessenger Communication library for Arduino & .NET
Other
208 stars 87 forks source link

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

Open sigmaeo opened 6 years ago

sigmaeo commented 6 years ago

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 commented 6 years ago

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

pauleffect90 commented 5 years ago

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.