Skip to content

Commit 08b1a8a

Browse files
authored
Merge pull request Tencent#1302 from chwarr/min-max-guard
Guard against min/max being macros in reader.h
2 parents 81af404 + 960b9cf commit 08b1a8a

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

include/rapidjson/reader.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ class GenericReader {
606606
parseResult_.Clear();
607607
state_ = IterativeParsingStartState;
608608
}
609-
609+
610610
//! Parse one token from JSON text
611611
/*! \tparam InputStream Type of input stream, implementing Stream concept
612612
\tparam Handler Type of handler, implementing Handler concept.
@@ -618,23 +618,23 @@ class GenericReader {
618618
bool IterativeParseNext(InputStream& is, Handler& handler) {
619619
while (RAPIDJSON_LIKELY(is.Peek() != '\0')) {
620620
SkipWhitespaceAndComments<parseFlags>(is);
621-
621+
622622
Token t = Tokenize(is.Peek());
623623
IterativeParsingState n = Predict(state_, t);
624624
IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler);
625-
625+
626626
// If we've finished or hit an error...
627627
if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) {
628628
// Report errors.
629629
if (d == IterativeParsingErrorState) {
630630
HandleError(state_, is);
631631
return false;
632632
}
633-
633+
634634
// Transition to the finish state.
635635
RAPIDJSON_ASSERT(d == IterativeParsingFinishState);
636636
state_ = d;
637-
637+
638638
// If StopWhenDone is not set...
639639
if (!(parseFlags & kParseStopWhenDoneFlag)) {
640640
// ... and extra non-whitespace data is found...
@@ -645,30 +645,30 @@ class GenericReader {
645645
return false;
646646
}
647647
}
648-
648+
649649
// Success! We are done!
650650
return true;
651651
}
652-
652+
653653
// Transition to the new state.
654654
state_ = d;
655655

656656
// If we parsed anything other than a delimiter, we invoked the handler, so we can return true now.
657657
if (!IsIterativeParsingDelimiterState(n))
658658
return true;
659659
}
660-
660+
661661
// We reached the end of file.
662662
stack_.Clear();
663663

664664
if (state_ != IterativeParsingFinishState) {
665665
HandleError(state_, is);
666666
return false;
667667
}
668-
668+
669669
return true;
670670
}
671-
671+
672672
//! Check if token-by-token parsing JSON text is complete
673673
/*! \return Whether the JSON has been fully decoded.
674674
*/
@@ -1523,7 +1523,7 @@ class GenericReader {
15231523
}
15241524
}
15251525
}
1526-
1526+
15271527
if (RAPIDJSON_UNLIKELY(!useNanOrInf)) {
15281528
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
15291529
}
@@ -1769,12 +1769,12 @@ class GenericReader {
17691769

17701770
// Single value state
17711771
IterativeParsingValueState,
1772-
1772+
17731773
// Delimiter states (at bottom)
17741774
IterativeParsingElementDelimiterState,
17751775
IterativeParsingMemberDelimiterState,
17761776
IterativeParsingKeyValueDelimiterState,
1777-
1777+
17781778
cIterativeParsingStateCount
17791779
};
17801780

@@ -2167,43 +2167,43 @@ class GenericReader {
21672167
RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const {
21682168
return s >= IterativeParsingElementDelimiterState;
21692169
}
2170-
2170+
21712171
RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const {
21722172
return s <= IterativeParsingErrorState;
21732173
}
2174-
2174+
21752175
template <unsigned parseFlags, typename InputStream, typename Handler>
21762176
ParseResult IterativeParse(InputStream& is, Handler& handler) {
21772177
parseResult_.Clear();
21782178
ClearStackOnExit scope(*this);
21792179
IterativeParsingState state = IterativeParsingStartState;
2180-
2180+
21812181
SkipWhitespaceAndComments<parseFlags>(is);
21822182
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
21832183
while (is.Peek() != '\0') {
21842184
Token t = Tokenize(is.Peek());
21852185
IterativeParsingState n = Predict(state, t);
21862186
IterativeParsingState d = Transit<parseFlags>(state, t, n, is, handler);
2187-
2187+
21882188
if (d == IterativeParsingErrorState) {
21892189
HandleError(state, is);
21902190
break;
21912191
}
2192-
2192+
21932193
state = d;
2194-
2194+
21952195
// Do not further consume streams if a root JSON has been parsed.
21962196
if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState)
21972197
break;
2198-
2198+
21992199
SkipWhitespaceAndComments<parseFlags>(is);
22002200
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
22012201
}
2202-
2202+
22032203
// Handle the end of file.
22042204
if (state != IterativeParsingFinishState)
22052205
HandleError(state, is);
2206-
2206+
22072207
return parseResult_;
22082208
}
22092209

test/unittest/itoatest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Tencent is pleased to support the open source community by making RapidJSON available.
2-
//
2+
//
33
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
44
//
55
// Licensed under the MIT License (the "License"); you may not use this file except
66
// in compliance with the License. You may obtain a copy of the License at
77
//
88
// http://opensource.org/licenses/MIT
99
//
10-
// Unless required by applicable law or agreed to in writing, software distributed
11-
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12-
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
// Unless required by applicable law or agreed to in writing, software distributed
11+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
// specific language governing permissions and limitations under the License.
1414

1515
#include "unittest.h"
@@ -61,7 +61,7 @@ static void VerifyValue(T value, void(*f)(T, char*), char* (*g)(T, char*)) {
6161

6262
f(value, buffer1);
6363
*g(value, buffer2) = '\0';
64-
64+
6565

6666
EXPECT_STREQ(buffer1, buffer2);
6767
}
@@ -79,12 +79,12 @@ static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) {
7979
do {
8080
VerifyValue<T>(i - 1, f, g);
8181
VerifyValue<T>(i, f, g);
82-
if (std::numeric_limits<T>::min() < 0) {
82+
if ((std::numeric_limits<T>::min)() < 0) {
8383
VerifyValue<T>(Traits<T>::Negate(i), f, g);
8484
VerifyValue<T>(Traits<T>::Negate(i + 1), f, g);
8585
}
8686
last = i;
87-
if (i > static_cast<T>(std::numeric_limits<T>::max() / static_cast<T>(power)))
87+
if (i > static_cast<T>((std::numeric_limits<T>::max)() / static_cast<T>(power)))
8888
break;
8989
i *= static_cast<T>(power);
9090
} while (last < i);

test/unittest/readertest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static void TestParseDouble() {
422422
"67546703537516986049910576551282076245490090389328944075868508455133942"
423423
"30458323690322294816580855933212334827479782620414472316873817718091929"
424424
"9881250404026184124858368",
425-
std::numeric_limits<double>::max());
425+
(std::numeric_limits<double>::max)());
426426

427427
TEST_DOUBLE(fullPrecision,
428428
"243546080556034731077856379609316893158278902575447060151047"

0 commit comments

Comments
 (0)