@@ -1247,18 +1247,27 @@ class GenericReader {
1247
1247
}
1248
1248
// Parse NaN or Infinity here
1249
1249
else if ((parseFlags & kParseNanAndInfFlag ) && RAPIDJSON_LIKELY ((s.Peek () == ' I' || s.Peek () == ' N' ))) {
1250
- useNanOrInf = true ;
1251
- if (RAPIDJSON_LIKELY (Consume (s, ' N' ) && Consume (s, ' a' ) && Consume (s, ' N' ))) {
1252
- d = std::numeric_limits<double >::quiet_NaN ();
1250
+ if (Consume (s, ' N' )) {
1251
+ if (Consume (s, ' a' ) && Consume (s, ' N' )) {
1252
+ d = std::numeric_limits<double >::quiet_NaN ();
1253
+ useNanOrInf = true ;
1254
+ }
1253
1255
}
1254
- else if (RAPIDJSON_LIKELY (Consume (s, ' I' ) && Consume (s, ' n' ) && Consume (s, ' f' ))) {
1255
- d = (minus ? -std::numeric_limits<double >::infinity () : std::numeric_limits<double >::infinity ());
1256
- if (RAPIDJSON_UNLIKELY (s.Peek () == ' i' && !(Consume (s, ' i' ) && Consume (s, ' n' )
1257
- && Consume (s, ' i' ) && Consume (s, ' t' ) && Consume (s, ' y' ))))
1258
- RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1256
+ else if (RAPIDJSON_LIKELY (Consume (s, ' I' ))) {
1257
+ if (Consume (s, ' n' ) && Consume (s, ' f' )) {
1258
+ d = (minus ? -std::numeric_limits<double >::infinity () : std::numeric_limits<double >::infinity ());
1259
+ useNanOrInf = true ;
1260
+
1261
+ if (RAPIDJSON_UNLIKELY (s.Peek () == ' i' && !(Consume (s, ' i' ) && Consume (s, ' n' )
1262
+ && Consume (s, ' i' ) && Consume (s, ' t' ) && Consume (s, ' y' )))) {
1263
+ RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1264
+ }
1265
+ }
1259
1266
}
1260
- else
1267
+
1268
+ if (RAPIDJSON_UNLIKELY (!useNanOrInf)) {
1261
1269
RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
1270
+ }
1262
1271
}
1263
1272
else
1264
1273
RAPIDJSON_PARSE_ERROR (kParseErrorValueInvalid , s.Tell ());
0 commit comments