Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: COBS.cpp
- Revision:
- 2:64fdac5efaa1
- Parent:
- 1:2b84a7482df6
- Child:
- 3:41c9f2bbeeb2
--- a/COBS.cpp Tue Feb 10 03:12:12 2015 +0000 +++ b/COBS.cpp Tue Jul 21 19:31:41 2015 -0400 @@ -51,13 +51,16 @@ * writing the output to the location pointed * to by “dst”. */ -void COBS::UnStuffData(unsigned char *ptr, unsigned long length, unsigned char *dst) +int COBS::UnStuffData(unsigned char *ptr, unsigned long length, unsigned char *dst) { const unsigned char *end = ptr + length; while (ptr < end) { int i, code = *ptr++; - for (i=1; i<code; i++) *dst++ = *ptr++; + if (ptr+code > end) return 1; //if we will overun the end of the buffer exit + //this is most likely to happen when decoding a malformed message + for (i=1; i<code; i++) *dst++ = *ptr++; if (code < 0xFF) *dst++ = 0; } -} \ No newline at end of file + return 0; +}