@@ -1170,18 +1170,27 @@ class GenericReader {
1170
1170
}
1171
1171
// Parse NaN or Infinity here
1172
1172
else if ((parseFlags & kParseNanAndInfFlag ) && RAPIDJSON_LIKELY ((s.Peek () == ' I' || s.Peek () == ' N' ))) {
1173
- useNanOrInf = true ;
1174
- if (RAPIDJSON_LIKELY (Consume (s, ' N' ) && Consume (s, ' a' ) && Consume (s, ' N' ))) {
1175
- d = std::numeric_limits<double >::quiet_NaN ();
1173
+ if (Consume (s, ' N' )) {
1174
+ if (Consume (s, ' a' ) && Consume (s, ' N' )) {
1175
+ d = std::numeric_limits<double >::quiet_NaN ();
1176
+ useNanOrInf = true ;
1177
+ }
1176
1178
}
1177
- else if (RAPIDJSON_LIKELY (Consume (s, ' I' ) && Consume (s, ' n' ) && Consume (s, ' f' ))) {
1178
- d = (minus ? -std::numeric_limits<double >::infinity () : std::numeric_limits<double >::infinity ());
1179
- if (RAPIDJSON_UNLIKELY (s.Peek () == ' i' && !(Consume (s, ' i' ) && Consume (s, ' n' )
1180
- && Consume (s, ' i' ) && Consume (s, ' t' ) && Consume (s, ' y' ))))
1181
- RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1179
+ else if (RAPIDJSON_LIKELY (Consume (s, ' I' ))) {
1180
+ if (Consume (s, ' n' ) && Consume (s, ' f' )) {
1181
+ d = (minus ? -std::numeric_limits<double >::infinity () : std::numeric_limits<double >::infinity ());
1182
+ useNanOrInf = true ;
1183
+
1184
+ if (RAPIDJSON_UNLIKELY (s.Peek () == ' i' && !(Consume (s, ' i' ) && Consume (s, ' n' )
1185
+ && Consume (s, ' i' ) && Consume (s, ' t' ) && Consume (s, ' y' )))) {
1186
+ RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1187
+ }
1188
+ }
1182
1189
}
1183
- else
1190
+
1191
+ if (RAPIDJSON_UNLIKELY (!useNanOrInf)) {
1184
1192
RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1193
+ }
1185
1194
}
1186
1195
else
1187
1196
RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
0 commit comments