Skip to content

Commit

Permalink
[SetupPayload] Set TLV buffer to null if there is no optional data
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Jun 1, 2020
1 parent 37a3675 commit 37174e2
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 37174e2

Please sign in to comment.