@@ -368,7 +368,7 @@ bool Reader::readComment() {
368
368
369
369
static std::string normalizeEOL (Reader::Location begin, Reader::Location end) {
370
370
std::string normalized;
371
- normalized.reserve (end - begin);
371
+ normalized.reserve (static_cast < size_t >( end - begin) );
372
372
Reader::Location current = begin;
373
373
while (current != end) {
374
374
char c = *current++;
@@ -578,7 +578,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
578
578
Char c = *current++;
579
579
if (c < ' 0' || c > ' 9' )
580
580
return decodeDouble (token, decoded);
581
- Value::UInt digit (c - ' 0' );
581
+ Value::UInt digit (static_cast <Value::UInt>( c - ' 0' ) );
582
582
if (value >= threshold) {
583
583
// We've hit or exceeded the max value divided by 10 (rounded down). If
584
584
// a) we've only just touched the limit, b) this is the last digit, and
@@ -636,7 +636,7 @@ bool Reader::decodeString(Token& token) {
636
636
}
637
637
638
638
bool Reader::decodeString (Token& token, std::string& decoded) {
639
- decoded.reserve (token.end_ - token.start_ - 2 );
639
+ decoded.reserve (static_cast < size_t >( token.end_ - token.start_ - 2 ) );
640
640
Location current = token.start_ + 1 ; // skip '"'
641
641
Location end = token.end_ - 1 ; // do not include '"'
642
642
while (current != end) {
@@ -720,13 +720,13 @@ bool Reader::decodeUnicodeCodePoint(Token& token,
720
720
bool Reader::decodeUnicodeEscapeSequence (Token& token,
721
721
Location& current,
722
722
Location end,
723
- unsigned int & unicode ) {
723
+ unsigned int & ret_unicode ) {
724
724
if (end - current < 4 )
725
725
return addError (
726
726
" Bad unicode escape sequence in string: four digits expected." ,
727
727
token,
728
728
current);
729
- unicode = 0 ;
729
+ int unicode = 0 ;
730
730
for (int index = 0 ; index < 4 ; ++index ) {
731
731
Char c = *current++;
732
732
unicode *= 16 ;
@@ -742,6 +742,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
742
742
token,
743
743
current);
744
744
}
745
+ ret_unicode = static_cast <unsigned int >(unicode);
745
746
return true ;
746
747
}
747
748
@@ -756,7 +757,7 @@ Reader::addError(const std::string& message, Token& token, Location extra) {
756
757
}
757
758
758
759
bool Reader::recoverFromError (TokenType skipUntilToken) {
759
- int errorCount = int ( errors_.size () );
760
+ size_t const errorCount = errors_.size ();
760
761
Token skip;
761
762
for (;;) {
762
763
if (!readToken (skip))
@@ -851,7 +852,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
851
852
}
852
853
853
854
bool Reader::pushError (const Value& value, const std::string& message) {
854
- size_t length = end_ - begin_;
855
+ ptrdiff_t const length = end_ - begin_;
855
856
if (value.getOffsetStart () > length
856
857
|| value.getOffsetLimit () > length)
857
858
return false ;
@@ -868,7 +869,7 @@ bool Reader::pushError(const Value& value, const std::string& message) {
868
869
}
869
870
870
871
bool Reader::pushError (const Value& value, const std::string& message, const Value& extra) {
871
- size_t length = end_ - begin_;
872
+ ptrdiff_t const length = end_ - begin_;
872
873
if (value.getOffsetStart () > length
873
874
|| value.getOffsetLimit () > length
874
875
|| extra.getOffsetLimit () > length)
@@ -918,8 +919,8 @@ class OurReader {
918
919
typedef char Char;
919
920
typedef const Char* Location;
920
921
struct StructuredError {
921
- size_t offset_start;
922
- size_t offset_limit;
922
+ ptrdiff_t offset_start;
923
+ ptrdiff_t offset_limit;
923
924
std::string message;
924
925
};
925
926
@@ -1560,7 +1561,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
1560
1561
Char c = *current++;
1561
1562
if (c < ' 0' || c > ' 9' )
1562
1563
return decodeDouble (token, decoded);
1563
- Value::UInt digit (c - ' 0' );
1564
+ Value::UInt digit (static_cast <Value::UInt>( c - ' 0' ) );
1564
1565
if (value >= threshold) {
1565
1566
// We've hit or exceeded the max value divided by 10 (rounded down). If
1566
1567
// a) we've only just touched the limit, b) this is the last digit, and
@@ -1596,12 +1597,13 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
1596
1597
double value = 0 ;
1597
1598
const int bufferSize = 32 ;
1598
1599
int count;
1599
- int length = int ( token.end_ - token.start_ ) ;
1600
+ ptrdiff_t const length = token.end_ - token.start_ ;
1600
1601
1601
1602
// Sanity check to avoid buffer overflow exploits.
1602
1603
if (length < 0 ) {
1603
1604
return addError (" Unable to parse token length" , token);
1604
1605
}
1606
+ size_t const ulength = static_cast <size_t >(length);
1605
1607
1606
1608
// Avoid using a string constant for the format control string given to
1607
1609
// sscanf, as this can cause hard to debug crashes on OS X. See here for more
@@ -1612,7 +1614,7 @@ bool OurReader::decodeDouble(Token& token, Value& decoded) {
1612
1614
1613
1615
if (length <= bufferSize) {
1614
1616
Char buffer[bufferSize + 1 ];
1615
- memcpy (buffer, token.start_ , length );
1617
+ memcpy (buffer, token.start_ , ulength );
1616
1618
buffer[length] = 0 ;
1617
1619
count = sscanf (buffer, format, &value);
1618
1620
} else {
@@ -1640,7 +1642,7 @@ bool OurReader::decodeString(Token& token) {
1640
1642
}
1641
1643
1642
1644
bool OurReader::decodeString (Token& token, std::string& decoded) {
1643
- decoded.reserve (token.end_ - token.start_ - 2 );
1645
+ decoded.reserve (static_cast < size_t >( token.end_ - token.start_ - 2 ) );
1644
1646
Location current = token.start_ + 1 ; // skip '"'
1645
1647
Location end = token.end_ - 1 ; // do not include '"'
1646
1648
while (current != end) {
@@ -1724,13 +1726,13 @@ bool OurReader::decodeUnicodeCodePoint(Token& token,
1724
1726
bool OurReader::decodeUnicodeEscapeSequence (Token& token,
1725
1727
Location& current,
1726
1728
Location end,
1727
- unsigned int & unicode ) {
1729
+ unsigned int & ret_unicode ) {
1728
1730
if (end - current < 4 )
1729
1731
return addError (
1730
1732
" Bad unicode escape sequence in string: four digits expected." ,
1731
1733
token,
1732
1734
current);
1733
- unicode = 0 ;
1735
+ int unicode = 0 ;
1734
1736
for (int index = 0 ; index < 4 ; ++index ) {
1735
1737
Char c = *current++;
1736
1738
unicode *= 16 ;
@@ -1746,6 +1748,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
1746
1748
token,
1747
1749
current);
1748
1750
}
1751
+ ret_unicode = static_cast <unsigned int >(unicode);
1749
1752
return true ;
1750
1753
}
1751
1754
@@ -1760,7 +1763,7 @@ OurReader::addError(const std::string& message, Token& token, Location extra) {
1760
1763
}
1761
1764
1762
1765
bool OurReader::recoverFromError (TokenType skipUntilToken) {
1763
- int errorCount = int ( errors_.size () );
1766
+ size_t errorCount = errors_.size ();
1764
1767
Token skip;
1765
1768
for (;;) {
1766
1769
if (!readToken (skip))
@@ -1850,7 +1853,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
1850
1853
}
1851
1854
1852
1855
bool OurReader::pushError (const Value& value, const std::string& message) {
1853
- size_t length = end_ - begin_;
1856
+ ptrdiff_t length = end_ - begin_;
1854
1857
if (value.getOffsetStart () > length
1855
1858
|| value.getOffsetLimit () > length)
1856
1859
return false ;
@@ -1867,7 +1870,7 @@ bool OurReader::pushError(const Value& value, const std::string& message) {
1867
1870
}
1868
1871
1869
1872
bool OurReader::pushError (const Value& value, const std::string& message, const Value& extra) {
1870
- size_t length = end_ - begin_;
1873
+ ptrdiff_t length = end_ - begin_;
1871
1874
if (value.getOffsetStart () > length
1872
1875
|| value.getOffsetLimit () > length
1873
1876
|| extra.getOffsetLimit () > length)
0 commit comments