Skip to content

Commit b257c92

Browse files
committed
"-Warray-bounds" ignore false positives
1 parent 76794ee commit b257c92

File tree

10 files changed

+289
-222
lines changed

10 files changed

+289
-222
lines changed

include/jsoncons/basic_json.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ namespace jsoncons {
18901890
parser.parse_some(decoder);
18911891
parser.finish_parse(decoder);
18921892
parser.check_done();
1893-
if (!decoder.is_valid())
1893+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
18941894
{
18951895
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json string"));
18961896
}
@@ -1916,7 +1916,7 @@ namespace jsoncons {
19161916
parser.parse_some(decoder);
19171917
parser.finish_parse(decoder);
19181918
parser.check_done();
1919-
if (!decoder.is_valid())
1919+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
19201920
{
19211921
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json string"));
19221922
}
@@ -1959,7 +1959,7 @@ namespace jsoncons {
19591959
basic_json_reader<char_type,stream_source<char_type>,Allocator> reader(is, decoder, options);
19601960
reader.read_next();
19611961
reader.check_done();
1962-
if (!decoder.is_valid())
1962+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
19631963
{
19641964
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json stream"));
19651965
}
@@ -1974,7 +1974,7 @@ namespace jsoncons {
19741974
basic_json_reader<char_type,stream_source<char_type>,Allocator> reader(is, decoder, options, alloc_set.get_temp_allocator());
19751975
reader.read_next();
19761976
reader.check_done();
1977-
if (!decoder.is_valid())
1977+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
19781978
{
19791979
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json stream"));
19801980
}
@@ -1992,7 +1992,7 @@ namespace jsoncons {
19921992
std::forward<InputIt>(last)), decoder, options);
19931993
reader.read_next();
19941994
reader.check_done();
1995-
if (!decoder.is_valid())
1995+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
19961996
{
19971997
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json from iterator pair"));
19981998
}
@@ -2009,7 +2009,7 @@ namespace jsoncons {
20092009
decoder, options, alloc_set.get_temp_allocator());
20102010
reader.read_next();
20112011
reader.check_done();
2012-
if (!decoder.is_valid())
2012+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
20132013
{
20142014
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json from iterator pair"));
20152015
}
@@ -2039,7 +2039,7 @@ namespace jsoncons {
20392039
basic_json_reader<char_type,stream_source<char_type>> reader(is, decoder, options, err_handler);
20402040
reader.read_next();
20412041
reader.check_done();
2042-
if (!decoder.is_valid())
2042+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
20432043
{
20442044
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json stream"));
20452045
}
@@ -2060,7 +2060,7 @@ namespace jsoncons {
20602060
basic_json_reader<char_type,iterator_source<InputIt>> reader(iterator_source<InputIt>(std::forward<InputIt>(first),std::forward<InputIt>(last)), decoder, options, err_handler);
20612061
reader.read_next();
20622062
reader.check_done();
2063-
if (!decoder.is_valid())
2063+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
20642064
{
20652065
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json from iterator pair"));
20662066
}
@@ -2087,7 +2087,7 @@ namespace jsoncons {
20872087
parser.parse_some(decoder);
20882088
parser.finish_parse(decoder);
20892089
parser.check_done();
2090-
if (!decoder.is_valid())
2090+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
20912091
{
20922092
JSONCONS_THROW(ser_error(json_errc::source_error, "Failed to parse json string"));
20932093
}

include/jsoncons/conv_result.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
namespace jsoncons {
1616

17+
// Ignore false positives
18+
#if defined(__GNUC__)
19+
# pragma GCC diagnostic push
20+
# pragma GCC diagnostic ignored "-Warray-bounds"
21+
#endif
22+
1723
template <typename T>
1824
class conv_result;
1925

@@ -245,6 +251,10 @@ swap(conv_result<T>& lhs, conv_result<T>& rhs) noexcept
245251
lhs.swap(rhs);
246252
}
247253

254+
#if defined(__GNUC__)
255+
# pragma GCC diagnostic pop
256+
#endif
257+
248258
} // jsoncons
249259

250260
#endif // JSONCONS_CONV_RESULT_HPP

include/jsoncons/decode_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace jsoncons {
4848
{
4949
JSONCONS_THROW(ser_error(ec, cursor.context().line(), cursor.context().column()));
5050
}
51-
else if (!decoder.is_valid())
51+
else if (JSONCONS_UNLIKELY(!decoder.is_valid()))
5252
{
5353
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, cursor.context().line(), cursor.context().column()));
5454
}

include/jsoncons/reflect/decode_json.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ try_decode_json(const Source& s,
4040
jsoncons::json_decoder<T> decoder;
4141
basic_json_reader<char_type, string_source<char_type>> reader(s, decoder, options);
4242
reader.read(ec);
43-
if (ec)
43+
if (JSONCONS_UNLIKELY(ec))
4444
{
4545
return result_type{read_error{ec, reader.line(), reader.column()}};
4646
}
47-
if (!decoder.is_valid())
47+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
4848
{
4949
return result_type{ read_error{conv_errc::conversion_failed, reader.line(), reader.column()} };
5050
}
@@ -63,7 +63,7 @@ try_decode_json(const Source& s,
6363

6464
std::error_code ec;
6565
basic_json_cursor<char_type,string_source<char_type>> cursor(s, options, default_json_parsing(), ec);
66-
if (ec)
66+
if (JSONCONS_UNLIKELY(ec))
6767
{
6868
return result_type{read_error{ec, cursor.line(), cursor.column()}};
6969
}
@@ -82,11 +82,11 @@ try_decode_json(std::basic_istream<CharT>& is,
8282
jsoncons::json_decoder<T> decoder;
8383
basic_json_reader<CharT, stream_source<CharT>> reader(is, decoder, options);
8484
reader.read(ec);
85-
if (ec)
85+
if (JSONCONS_UNLIKELY(ec))
8686
{
8787
return result_type{read_error{ec, reader.line(), reader.column()}};
8888
}
89-
if (!decoder.is_valid())
89+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
9090
{
9191
return result_type(read_error(conv_errc::conversion_failed, reader.line(), reader.column()));
9292
}
@@ -103,7 +103,7 @@ try_decode_json(std::basic_istream<CharT>& is,
103103

104104
std::error_code ec;
105105
basic_json_cursor<CharT> cursor(is, options, default_json_parsing(), ec);
106-
if (ec)
106+
if (JSONCONS_UNLIKELY(ec))
107107
{
108108
return result_type{read_error{ec, cursor.line(), cursor.column()}};
109109
}
@@ -124,11 +124,11 @@ try_decode_json(InputIt first, InputIt last,
124124
jsoncons::json_decoder<T> decoder;
125125
basic_json_reader<char_type, iterator_source<InputIt>> reader(iterator_source<InputIt>(first,last), decoder, options);
126126
reader.read(ec);
127-
if (ec)
127+
if (JSONCONS_UNLIKELY(ec))
128128
{
129129
return result_type{read_error{ec, reader.line(), reader.column()}};
130130
}
131-
if (!decoder.is_valid())
131+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
132132
{
133133
return result_type(read_error(conv_errc::conversion_failed, reader.line(), reader.column()));
134134
}
@@ -148,7 +148,7 @@ try_decode_json(InputIt first, InputIt last,
148148
std::error_code ec;
149149
basic_json_cursor<char_type,iterator_source<InputIt>> cursor(iterator_source<InputIt>(first, last),
150150
options, default_json_parsing(), ec);
151-
if (ec)
151+
if (JSONCONS_UNLIKELY(ec))
152152
{
153153
return result_type{read_error{ec, cursor.line(), cursor.column()}};
154154
}
@@ -173,11 +173,11 @@ try_decode_json(const allocator_set<Allocator,TempAllocator>& alloc_set,
173173
std::error_code ec;
174174
basic_json_reader<char_type, string_source<char_type>,TempAllocator> reader(s, decoder, options, alloc_set.get_temp_allocator());
175175
reader.read(ec);
176-
if (ec)
176+
if (JSONCONS_UNLIKELY(ec))
177177
{
178178
return result_type{read_error{ec, reader.line(), reader.column()}};
179179
}
180-
if (!decoder.is_valid())
180+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
181181
{
182182
return result_type(read_error(conv_errc::conversion_failed, reader.line(), reader.column()));
183183
}
@@ -198,7 +198,7 @@ try_decode_json(const allocator_set<Allocator,TempAllocator>& alloc_set,
198198
std::error_code ec;
199199
basic_json_cursor<char_type,string_source<char_type>,TempAllocator> cursor(
200200
std::allocator_arg, alloc_set.get_temp_allocator(), s, options, default_json_parsing(), ec);
201-
if (ec)
201+
if (JSONCONS_UNLIKELY(ec))
202202
{
203203
return result_type{read_error{ec, cursor.line(), cursor.column()}};
204204
}
@@ -219,11 +219,11 @@ try_decode_json(const allocator_set<Allocator,TempAllocator>& alloc_set,
219219
std::error_code ec;
220220
basic_json_reader<CharT, stream_source<CharT>,TempAllocator> reader(is, decoder, options, alloc_set.get_temp_allocator());
221221
reader.read(ec);
222-
if (ec)
222+
if (JSONCONS_UNLIKELY(ec))
223223
{
224224
return result_type{read_error{ec, reader.line(), reader.column()}};
225225
}
226-
if (!decoder.is_valid())
226+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
227227
{
228228
return result_type(read_error(conv_errc::conversion_failed, reader.line(), reader.column()));
229229
}
@@ -237,13 +237,13 @@ try_decode_json(const allocator_set<Allocator,TempAllocator>& alloc_set,
237237
const basic_json_decode_options<CharT>& options = basic_json_decode_options<CharT>())
238238
{
239239
using value_type = T;
240-
using char_type = CharT;
241240
using result_type = read_result<value_type>;
241+
using char_type = CharT;
242242

243243
std::error_code ec;
244244
basic_json_cursor<char_type,stream_source<char_type>,TempAllocator> cursor(
245245
std::allocator_arg, alloc_set.get_temp_allocator(), is, options, ec);
246-
if (ec)
246+
if (JSONCONS_UNLIKELY(ec))
247247
{
248248
return result_type{read_error{ec, cursor.line(), cursor.column()}};
249249
}

include/jsoncons/reflect/decode_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct decode_traits
6060

6161
using json_type = basic_json<CharT>;
6262
auto j = try_to_json<json_type>(cursor, ec);
63-
if (ec)
63+
if (JSONCONS_UNLIKELY(ec))
6464
{
6565
return result_type(read_error{ec, cursor.line(), cursor.column()});
6666
}

include/jsoncons_ext/bson/decode_bson.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace bson {
3737
auto adaptor = make_json_visitor_adaptor<json_visitor>(decoder);
3838
basic_bson_reader<jsoncons::bytes_source> reader(v, adaptor, options);
3939
reader.read();
40-
if (!decoder.is_valid())
40+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
4141
{
4242
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, reader.line(), reader.column()));
4343
}
@@ -71,7 +71,7 @@ namespace bson {
7171
auto adaptor = make_json_visitor_adaptor<json_visitor>(decoder);
7272
bson_stream_reader reader(is, adaptor, options);
7373
reader.read();
74-
if (!decoder.is_valid())
74+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
7575
{
7676
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, reader.line(), reader.column()));
7777
}
@@ -104,7 +104,7 @@ namespace bson {
104104
auto adaptor = make_json_visitor_adaptor<json_visitor>(decoder);
105105
basic_bson_reader<binary_iterator_source<InputIt>> reader(binary_iterator_source<InputIt>(first, last), adaptor, options);
106106
reader.read();
107-
if (!decoder.is_valid())
107+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
108108
{
109109
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, reader.line(), reader.column()));
110110
}
@@ -141,7 +141,7 @@ namespace bson {
141141
auto adaptor = make_json_visitor_adaptor<json_visitor>(decoder);
142142
basic_bson_reader<jsoncons::bytes_source,TempAllocator> reader(v, adaptor, options, alloc_set.get_temp_allocator());
143143
reader.read();
144-
if (!decoder.is_valid())
144+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
145145
{
146146
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, reader.line(), reader.column()));
147147
}
@@ -177,7 +177,7 @@ namespace bson {
177177
auto adaptor = make_json_visitor_adaptor<json_visitor>(decoder);
178178
basic_bson_reader<jsoncons::binary_stream_source,TempAllocator> reader(is, adaptor, options, alloc_set.get_temp_allocator());
179179
reader.read();
180-
if (!decoder.is_valid())
180+
if (JSONCONS_UNLIKELY(!decoder.is_valid()))
181181
{
182182
JSONCONS_THROW(ser_error(conv_errc::conversion_failed, reader.line(), reader.column()));
183183
}

0 commit comments

Comments
 (0)