Skip to content

Commit

Permalink
parser unit tests: Do not use auto, use reinterpret_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlongland committed Sep 7, 2021
1 parent 62c71df commit 96158b9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/parser/tst_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,30 +759,30 @@ void tst_Parser::mapsAndArrays()

static const CborParserOperations byteArrayOps = {
/* can_read_bytes = */ [](const CborValue *value, size_t len) {
auto data = static_cast<QByteArray *>(value->parser->data.ctx);
auto consumed = uintptr_t(value->source.token);
QByteArray *data = static_cast<QByteArray *>(value->parser->data.ctx);
uintptr_t consumed = uintptr_t(value->source.token);
return uintptr_t(data->size()) - consumed >= uintptr_t(len);
},
/* read_bytes = */ [](const CborValue *value, void *dst, size_t offset, size_t len) {
auto data = static_cast<QByteArray *>(value->parser->data.ctx);
auto consumed = uintptr_t(value->source.token);
QByteArray *data = static_cast<QByteArray *>(value->parser->data.ctx);
uintptr_t consumed = uintptr_t(value->source.token);
return memcpy(dst, data->constData() + consumed + offset, len);
},
/* advance_bytes = */ [](CborValue *value, size_t len) {
auto consumed = uintptr_t(value->source.token);
consumed += int(len);
value->source.token = (void*)consumed;
uintptr_t consumed = uintptr_t(value->source.token);
consumed += uintptr_t(len);
value->source.token = reinterpret_cast<void *>(consumed);
},
/* transfer_string = */ [](CborValue *value, const void **userptr, size_t offset, size_t len) {
// ###
auto data = static_cast<QByteArray *>(value->parser->data.ctx);
auto consumed = uintptr_t(value->source.token);
QByteArray *data = static_cast<QByteArray *>(value->parser->data.ctx);
uintptr_t consumed = uintptr_t(value->source.token);
if (uintptr_t(data->size()) - consumed < uintptr_t(len + offset))
return CborErrorUnexpectedEOF;
consumed += int(offset);
consumed += uintptr_t(offset);
*userptr = data->constData() + consumed;
consumed += int(len);
value->source.token = (void*)consumed;
consumed += uintptr_t(len);
value->source.token = reinterpret_cast<void *>(consumed);
return CborNoError;
}
};
Expand Down

0 comments on commit 96158b9

Please sign in to comment.