Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.2.0
-
None
Description
Preparations (or just take a look at the proposed solution and the code, and it'll make sense): Create an NDEF message that contains multiple records. The first record contains a payload (e.g., length = 10), the second doesn't contain a payload (length = 0).
Write this NDEF message to a tag (or convert it into a byte array).
Now read the byte array into a message using QNdefMessage::fromByteArray()
Expected outcome: the records are the same that were initially put into the message.
Actual outcome: the created records contain wrong data. The first record is fine, but the second also the payload set to length = 10 (instead of length = 0, as should be the case.
Reason: The loop that parses the NDEF message doesn't reset the data in the "record" variable after a record has been constructed and the loop moves on to the next record.
This means that if the first record sets specific data (like the payload, ID, etc.) and the second record doesn't override it, the data of the first record will still be present in the second record.
Proposed solution: Change lines 215+ of qndefmessage.cpp from:
if (!cf) {
result.append(record);
}
To:
if (!cf) {
result.append(record);
record = QNdefRecord();
}