@@ -990,22 +990,44 @@ static void chunkedStringTest(const QByteArray &data, const QString &concatenate
990
990
err = cbor_value_calculate_string_length (©, &n);
991
991
QVERIFY2 (!err, QByteArray (" Got error \" " ) + cbor_error_string (err) + " \" " );
992
992
993
- QByteArray buffer (n, Qt::Uninitialized);
993
+ size_t nn = n;
994
+ QByteArray buffer (n + 1 , Qt::Uninitialized);
995
+ QByteArray buffer2 (n + 1 , Qt::Uninitialized);
996
+ buffer[int (n)] = 0xff ;
997
+ buffer2[int (n)] = 0xff ;
994
998
QString formatted;
995
999
if (cbor_value_is_byte_string (©)) {
996
- err = cbor_value_copy_byte_string (©, (uint8_t *)buffer.data (), &n , nullptr );
1000
+ err = cbor_value_copy_byte_string (©, (uint8_t *)buffer.data (), &nn , nullptr );
997
1001
QVERIFY2 (!err, QByteArray (" Got error \" " ) + cbor_error_string (err) + " \" " );
998
- QCOMPARE (int (n), buffer. size () );
1002
+ QCOMPARE (nn, n );
999
1003
1000
- formatted = QString::fromLatin1 (" h'" + buffer.toHex () + ' \' ' );
1004
+ formatted = QString::fromLatin1 (" h'" + QByteArray::fromRawData (buffer.data (), n).toHex () + ' \' ' );
1005
+
1006
+ // repeat by allowing the null termination
1007
+ nn = n + 1 ;
1008
+ err = cbor_value_copy_byte_string (©, (uint8_t *)buffer2.data (), &nn, nullptr );
1001
1009
} else {
1002
1010
err = cbor_value_copy_text_string (©, buffer.data (), &n, nullptr );
1003
1011
QVERIFY2 (!err, QByteArray (" Got error \" " ) + cbor_error_string (err) + " \" " );
1004
- QCOMPARE (int (n), buffer. size () );
1012
+ QCOMPARE (nn, n );
1005
1013
1006
1014
formatted = ' "' + QString::fromUtf8 (buffer.data (), n) + ' "' ;
1015
+
1016
+ // repeat by allowing the null termination
1017
+ nn = n + 1 ;
1018
+ err = cbor_value_copy_text_string (©, buffer2.data (), &nn, nullptr );
1007
1019
}
1020
+ QVERIFY2 (!err, QByteArray (" Got error \" " ) + cbor_error_string (err) + " \" " );
1008
1021
QCOMPARE (formatted, concatenated);
1022
+
1023
+ // verify terminators
1024
+ QCOMPARE (buffer.at (n), char (0xff ));
1025
+ QCOMPARE (buffer2.at (n), ' \0 ' );
1026
+ QCOMPARE (nn, n);
1027
+
1028
+ buffer.truncate (n);
1029
+ buffer2.truncate (n);
1030
+ QCOMPARE (buffer2, buffer);
1009
1031
}
1010
1032
1011
1033
// confirm that the extra string we appended is still here
0 commit comments