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