Skip to content

Commit

Permalink
Added fix for duplication scenario (#16)
Browse files Browse the repository at this point in the history
* Added fix for duplication scenario

* Minor whitespace fix
  • Loading branch information
jeppefrandsen authored Sep 12, 2019
1 parent cf73b09 commit 76bf421
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.vscode/settings.json
.build-*
.build*
3 changes: 2 additions & 1 deletion include/Hdlcpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ class Hdlcpp {
result = -EIO;
}

discardBytes = i;
// Be sure to discard bytes (could be that destinationIndex > i in some cases)
discardBytes = destinationIndex > i ? destinationIndex : i;
resetValues();
}

Expand Down
18 changes: 18 additions & 0 deletions test/src/TestHdlcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,22 @@ TEST_CASE_METHOD(HdlcppFixture, "hdlcpp test", "[single-file]")
readBuffer.assign(frame1, frame1 + sizeof(frame1));
CHECK(hdlcpp->read(buffer, sizeof(buffer)) == 2);
}

SECTION("Test duplication scenario")
{
// Frames captured from duplication scenario
const uint8_t frame1[] = { 0x7e, 0xff };
const uint8_t frame2[] = { 0x12, 0x4a, 0x07, 0x0a, 0x01, 0x03, 0x18, 0x07, 0x20, 0x64, 0xd5, 0x97 };
const uint8_t frame3[] = { 0x7e };
const uint8_t frame4[] = { 0x7e, 0xff, 0x61, 0x08, 0x82 };

readBuffer.assign(frame1, frame1 + sizeof(frame1));
CHECK(hdlcpp->read(buffer, sizeof(buffer)) == -ENOMSG);
readBuffer.assign(frame2, frame2 + sizeof(frame2));
CHECK(hdlcpp->read(buffer, sizeof(buffer)) == -ENOMSG);
readBuffer.assign(frame3, frame3 + sizeof(frame3));
CHECK(hdlcpp->read(buffer, sizeof(buffer)) == 9);
readBuffer.assign(frame4, frame4 + sizeof(frame4));
CHECK(hdlcpp->read(buffer, sizeof(buffer)) == -ENOMSG);
}
}

0 comments on commit 76bf421

Please sign in to comment.