OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/json/json_parser.h" | 5 #include "base/json/json_parser.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 if (*pos_ == '-') | 673 if (*pos_ == '-') |
674 NextChar(); | 674 NextChar(); |
675 | 675 |
676 if (!ReadInt(false)) { | 676 if (!ReadInt(false)) { |
677 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 677 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
678 return nullptr; | 678 return nullptr; |
679 } | 679 } |
680 end_index = index_; | 680 end_index = index_; |
681 | 681 |
682 // The optional fraction part. | 682 // The optional fraction part. |
683 if (*pos_ == '.') { | 683 if (pos_ < end_pos_ && *pos_ == '.') { |
684 if (!CanConsume(1)) { | 684 if (!CanConsume(1)) { |
685 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 685 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
686 return nullptr; | 686 return nullptr; |
687 } | 687 } |
688 NextChar(); | 688 NextChar(); |
689 if (!ReadInt(true)) { | 689 if (!ReadInt(true)) { |
690 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 690 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
691 return nullptr; | 691 return nullptr; |
692 } | 692 } |
693 end_index = index_; | 693 end_index = index_; |
694 } | 694 } |
695 | 695 |
696 // Optional exponent part. | 696 // Optional exponent part. |
697 if (*pos_ == 'e' || *pos_ == 'E') { | 697 if (pos_ < end_pos_ && (*pos_ == 'e' || *pos_ == 'E')) { |
dcheng
2017/02/24 21:15:31
Should lines 697 to 713 be wrapped in a pos_ < end
Robert Sesek
2017/02/24 21:25:33
That's what this is... are you asking about line 7
dcheng
2017/02/24 21:55:45
I can't read, so ignore this.
Robert Sesek
2017/02/24 22:16:22
end_pos_ is start_pos_+length, so it points at the
| |
698 if (!CanConsume(1)) { | |
699 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | |
700 return nullptr; | |
701 } | |
698 NextChar(); | 702 NextChar(); |
699 if (*pos_ == '-' || *pos_ == '+') | 703 if (!CanConsume(1)) { |
704 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | |
705 return nullptr; | |
706 } | |
707 if (*pos_ == '-' || *pos_ == '+') { | |
700 NextChar(); | 708 NextChar(); |
709 if (!CanConsume(1)) { | |
710 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | |
711 return nullptr; | |
712 } | |
713 } | |
701 if (!ReadInt(true)) { | 714 if (!ReadInt(true)) { |
702 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); | 715 ReportError(JSONReader::JSON_SYNTAX_ERROR, 1); |
703 return nullptr; | 716 return nullptr; |
704 } | 717 } |
705 end_index = index_; | 718 end_index = index_; |
706 } | 719 } |
707 | 720 |
708 // ReadInt is greedy because numbers have no easily detectable sentinel, | 721 // ReadInt is greedy because numbers have no easily detectable sentinel, |
709 // so save off where the parser should be on exit (see Consume invariant at | 722 // so save off where the parser should be on exit (see Consume invariant at |
710 // the top of the header), then make sure the next token is one which is | 723 // the top of the header), then make sure the next token is one which is |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
818 const std::string& description) { | 831 const std::string& description) { |
819 if (line || column) { | 832 if (line || column) { |
820 return StringPrintf("Line: %i, column: %i, %s", | 833 return StringPrintf("Line: %i, column: %i, %s", |
821 line, column, description.c_str()); | 834 line, column, description.c_str()); |
822 } | 835 } |
823 return description; | 836 return description; |
824 } | 837 } |
825 | 838 |
826 } // namespace internal | 839 } // namespace internal |
827 } // namespace base | 840 } // namespace base |
OLD | NEW |