Skip to content

Commit

Permalink
[qt5cpp] Add nullptr guard to prevent crash when empty model is being…
Browse files Browse the repository at this point in the history
… serialized (#7434)

* Small fixes to prevent crash when empty json body is provided.

* Updated PetStore example for Qt5
  • Loading branch information
etherealjoy authored and wing328 committed Jan 19, 2018
1 parent 30c1448 commit ea4b948
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define {{prefix}}_HELPERS_H

#include <QJsonValue>
#include <QList>
#include <QMap>

{{#cppNamespaceDeclarations}}
namespace {{this}} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ QJsonObject*
QJsonObject* obj = new QJsonObject();
{{#vars}}
{{^isContainer}}{{#complexType}}{{^isString}}{{^isDate}}{{^isDateTime}}{{^isByteArray}}
if({{name}}->isSet()){
if(({{name}} != nullptr) && ({{name}}->isSet())){
toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
}{{/isByteArray}}{{/isDateTime}}{{/isDate}}{{/isString}}{{#isString}}
if({{name}} != nullptr && *{{name}} != QString("")){
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/qt5cpp/client/SWGHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define SWG_HELPERS_H

#include <QJsonValue>
#include <QList>
#include <QMap>

namespace Swagger {

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/qt5cpp/client/SWGPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ SWGPet::asJsonObject() {
obj->insert("id", QJsonValue(id));
}

if(category->isSet()){
if((category != nullptr) && (category->isSet())){
toJsonValue(QString("category"), category, obj, QString("SWGCategory"));
}

Expand Down

0 comments on commit ea4b948

Please sign in to comment.