Skip to content

Commit 2a2a0b8

Browse files
committed
Fix issues reported by VC++ Code Analysis
1 parent f92980f commit 2a2a0b8

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

GraphQLResponse.cpp

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace response {
1111

1212
Value::Value(Type type /*= Type::Null*/)
1313
: _type(type)
14+
, _boolean(false)
15+
, _int(0)
16+
, _float(0.0)
1417
{
1518
switch (type)
1619
{
@@ -28,18 +31,6 @@ Value::Value(Type type /*= Type::Null*/)
2831
_string.reset(new StringType());
2932
break;
3033

31-
case Type::Boolean:
32-
_boolean = false;
33-
break;
34-
35-
case Type::Int:
36-
_int = 0;
37-
break;
38-
39-
case Type::Float:
40-
_float = 0;
41-
break;
42-
4334
case Type::Scalar:
4435
_scalar.reset(new Value());
4536
break;
@@ -52,34 +43,49 @@ Value::Value(Type type /*= Type::Null*/)
5243
Value::Value(StringType&& value)
5344
: _type(Type::String)
5445
, _string(new StringType(std::move(value)))
46+
, _boolean(false)
47+
, _int(0)
48+
, _float(0.0)
5549
{
5650
}
5751

5852
Value::Value(BooleanType value)
5953
: _type(Type::Boolean)
60-
, _boolean(value)
54+
, _boolean(false)
55+
, _int(0)
56+
, _float(0.0)
6157
{
58+
_boolean = value;
6259
}
6360

6461
Value::Value(IntType value)
6562
: _type(Type::Int)
66-
, _int(value)
63+
, _boolean(false)
64+
, _int(0)
65+
, _float(0.0)
6766
{
67+
_int = value;
6868
}
6969

7070
Value::Value(FloatType value)
7171
: _type(Type::Float)
72-
, _float(value)
72+
, _boolean(false)
73+
, _int(0)
74+
, _float(0.0)
7375
{
76+
_float = value;
7477
}
7578

76-
Value::Value(Value&& other)
79+
Value::Value(Value&& other) noexcept
7780
: _type(other._type)
7881
, _members(std::move(other._members))
7982
, _map(std::move(other._map))
8083
, _list(std::move(other._list))
8184
, _string(std::move(other._string))
8285
, _scalar(std::move(other._scalar))
86+
, _boolean(false)
87+
, _int(0)
88+
, _float(0.0)
8389
{
8490
switch (_type)
8591
{
@@ -98,10 +104,18 @@ Value::Value(Value&& other)
98104
default:
99105
break;
100106
}
107+
108+
const_cast<Type&>(other._type) = Type::Null;
109+
other._boolean = false;
110+
other._int = 0;
111+
other._float = 0.0;
101112
}
102113

103114
Value::Value(const Value& other)
104115
: _type(other._type)
116+
, _boolean(false)
117+
, _int(0)
118+
, _float(0.0)
105119
{
106120
switch (_type)
107121
{
@@ -140,7 +154,7 @@ Value::Value(const Value& other)
140154
}
141155
}
142156

143-
Value& Value::operator=(Value&& rhs)
157+
Value& Value::operator=(Value&& rhs) noexcept
144158
{
145159
const_cast<Type&>(_type) = rhs._type;
146160
const_cast<Type&>(rhs._type) = Type::Null;
@@ -150,19 +164,25 @@ Value& Value::operator=(Value&& rhs)
150164
_list = std::move(rhs._list);
151165
_string = std::move(rhs._string);
152166
_scalar = std::move(rhs._scalar);
167+
_boolean = false;
168+
_int = 0;
169+
_float = 0.0;
153170

154171
switch (_type)
155172
{
156173
case Type::Boolean:
157174
_boolean = rhs._boolean;
175+
rhs._boolean = false;
158176
break;
159177

160178
case Type::Int:
161179
_int = rhs._int;
180+
rhs._int = 0;
162181
break;
163182

164183
case Type::Float:
165184
_float = rhs._float;
185+
rhs._float = 0.0;
166186
break;
167187

168188
default:

include/graphqlservice/GraphQLResponse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ struct Value
4848
explicit Value(IntType value);
4949
explicit Value(FloatType value);
5050

51-
Value(Value&& other);
51+
Value(Value&& other) noexcept;
5252
explicit Value(const Value& other);
5353

54-
Value& operator=(Value&& rhs);
54+
Value& operator=(Value&& rhs) noexcept;
5555
Value& operator=(const Value& rhs) = delete;
5656

5757
// Check the Type

0 commit comments

Comments
 (0)