Skip to content

Commit

Permalink
Merge pull request #928 from vivien-apple/SetupPayload-TLVDataNULLBuf…
Browse files Browse the repository at this point in the history
…ferIfEmpty

[SetupPayload] Set TLV buffer to null if there is no optional data
  • Loading branch information
saurabhst authored Jun 1, 2020
2 parents 079c236 + 37174e2 commit 43cb72c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/setup_payload/QRCodeSetupPayloadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ static CHIP_ERROR payloadBinaryRepresentationWithTLV(SetupPayload & setupPayload

CHIP_ERROR QRCodeSetupPayloadGenerator::payloadBinaryRepresentation(string & binaryRepresentation)
{
uint8_t tlvDataStart[kTotalPayloadDataSizeInBytes];
return payloadBinaryRepresentation(binaryRepresentation, tlvDataStart, sizeof(tlvDataStart));
return payloadBinaryRepresentation(binaryRepresentation, NULL, 0);
}

CHIP_ERROR QRCodeSetupPayloadGenerator::payloadBinaryRepresentation(string & binaryRepresentation, uint8_t * tlvDataStart,
Expand Down Expand Up @@ -227,8 +226,9 @@ static CHIP_ERROR payloadBase41RepresentationWithTLV(SetupPayload & setupPayload

CHIP_ERROR QRCodeSetupPayloadGenerator::payloadBase41Representation(string & base41Representation)
{
uint8_t tlvDataStart[kTotalPayloadDataSizeInBytes];
return payloadBase41Representation(base41Representation, tlvDataStart, sizeof(tlvDataStart));
// 6.1.2.2. Table: Packed Binary Data Structure
// The TLV Data should be 0 length if TLV is not included.
return payloadBase41Representation(base41Representation, NULL, 0);
}

CHIP_ERROR QRCodeSetupPayloadGenerator::payloadBase41Representation(string & base41Representation, uint8_t * tlvDataStart,
Expand Down
2 changes: 1 addition & 1 deletion src/setup_payload/QRCodeSetupPayloadParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static CHIP_ERROR populateTLV(SetupPayload & outPayload, const vector<uint8_t> &
}
size_t bitsLeftToRead = (buf.size() * 8) - index;
size_t tlvBytesLength = ceil(double(bitsLeftToRead) / 8);
uint8_t * tlvArray = new uint8_t[tlvBytesLength]; // TODO: Allow caller to allocate buffer #825
uint8_t * tlvArray = new uint8_t[tlvBytesLength];
for (size_t i = 0; i < tlvBytesLength; i++)
{
uint64_t dest;
Expand Down
3 changes: 2 additions & 1 deletion src/setup_payload/tests/TestQRCodeTLV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ void TestSimpleRead(nlTestSuite * inSuite, void * inContext)

void TestOptionalDataWriteSerial(nlTestSuite * inSuite, void * inContext)
{
SetupPayload inPayload = GetDefaultPayloadWithSerialNumber();
SetupPayload inPayload = GetDefaultPayload();
inPayload.serialNumber = "1";

QRCodeSetupPayloadGenerator generator(inPayload);
string result;
Expand Down

0 comments on commit 43cb72c

Please sign in to comment.