Skip to content

Commit 863a480

Browse files
Fix #51: correct OOM reporting in cbor_encoder_create_{array,map}
If the OOM condition happened on the encoding of the type and item count, those two functions failed to return an error indicating that there was an OOM. We had a unit test for this, but due to an off-by-one error, we never actually tested the condition and just reported a false positive. Signed-off-by: Thiago Macieira <[email protected]>
1 parent 9ba4791 commit 863a480

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/cborencoder.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
466466
} else {
467467
err = encode_number_no_update(container, length, shiftedMajorType);
468468
}
469-
if (err && !isOomError(err))
470-
return err;
471-
472-
return CborNoError;
469+
return err;
473470
}
474471

475472
/**

tests/encoder/tst_encoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void tst_Encoder::shortBuffer()
599599
QFETCH(QByteArray, output);
600600
QByteArray buffer(output.length(), Qt::Uninitialized);
601601

602-
for (int len = 0; len < output.length() - 1; ++len) {
602+
for (int len = 0; len < output.length(); ++len) {
603603
CborEncoder encoder;
604604
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), len, 0);
605605
QCOMPARE(int(encodeVariant(&encoder, input)), int(CborErrorOutOfMemory));

0 commit comments

Comments
 (0)