From 271764cddf324d41d1ec2bf6de221bc8b376390e Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Sat, 24 Aug 2024 14:19:06 +0200 Subject: [PATCH] Assert if QGrpcOperationContext::serializer returns null QGrpcOperationContext shall be constructed with the valid serializer. Let's avoid unnecessary error handling and assert if QGrpcOperationContext doesn't contain a valid pointer to a serializer. [ChangeLog][Grpc] QAbstractGrpcChannel implementations now are obliged to supply QGrpcContext with the valid serializer. Any attempt to deserialize the returned message with null serializer now will lead to assert or SEGV. Pick-to: 6.8 Change-Id: I1f9142244bf5b5ba7a3d04965649d0a0fbb143b9 Reviewed-by: Dennis Oberst --- src/grpc/qgrpcoperation.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/grpc/qgrpcoperation.cpp b/src/grpc/qgrpcoperation.cpp index f81ec5d5..614c67fa 100644 --- a/src/grpc/qgrpcoperation.cpp +++ b/src/grpc/qgrpcoperation.cpp @@ -116,7 +116,8 @@ bool QGrpcOperation::read(QProtobufMessage *message) const "Can't read to nullptr QProtobufMessage"); Q_D(const QGrpcOperation); const auto ser = d->operationContext->serializer(); - return ser && ser->deserialize(message, d->data); + Q_ASSERT_X(ser, "QGrpcOperation", "The serializer is null"); + return ser->deserialize(message, d->data); } /*! @@ -144,8 +145,7 @@ QAbstractProtobufSerializer::DeserializationError QGrpcOperation::deserializatio { Q_D(const QGrpcOperation); const auto ser = d->operationContext->serializer(); - if (!ser) - return QAbstractProtobufSerializer::NoDeserializerError; + Q_ASSERT_X(ser, "QGrpcOperation", "The serializer is null"); return ser->deserializationError(); } @@ -160,8 +160,7 @@ QString QGrpcOperation::deserializationErrorString() const { Q_D(const QGrpcOperation); const auto ser = d->operationContext->serializer(); - if (!ser) - return QStringLiteral("serializer not available"); + Q_ASSERT_X(ser, "QGrpcOperation", "The serializer is null"); return ser->deserializationErrorString(); }