@@ -368,7 +368,7 @@ bool Reader::readComment() {
368368
369369static std::string normalizeEOL (Reader::Location begin, Reader::Location end) {
370370 std::string normalized;
371- normalized.reserve (end - begin);
371+ normalized.reserve (static_cast < size_t >( end - begin) );
372372 Reader::Location current = begin;
373373 while (current != end) {
374374 char c = *current++;
@@ -578,7 +578,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
578578 Char c = *current++;
579579 if (c < ' 0' || c > ' 9' )
580580 return decodeDouble (token, decoded);
581- Value::UInt digit (c - ' 0' );
581+ Value::UInt digit (static_cast <Value::UInt>( c - ' 0' ) );
582582 if (value >= threshold) {
583583 // We've hit or exceeded the max value divided by 10 (rounded down). If
584584 // a) we've only just touched the limit, b) this is the last digit, and
@@ -636,7 +636,7 @@ bool Reader::decodeString(Token& token) {
636636}
637637
638638bool 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 ) );
640640 Location current = token.start_ + 1 ; // skip '"'
641641 Location end = token.end_ - 1 ; // do not include '"'
642642 while (current != end) {
@@ -720,13 +720,13 @@ bool Reader::decodeUnicodeCodePoint(Token& token,
720720bool Reader::decodeUnicodeEscapeSequence (Token& token,
721721 Location& current,
722722 Location end,
723- unsigned int & unicode ) {
723+ unsigned int & ret_unicode ) {
724724 if (end - current < 4 )
725725 return addError (
726726 " Bad unicode escape sequence in string: four digits expected." ,
727727 token,
728728 current);
729- unicode = 0 ;
729+ int unicode = 0 ;
730730 for (int index = 0 ; index < 4 ; ++index) {
731731 Char c = *current++;
732732 unicode *= 16 ;
@@ -742,6 +742,7 @@ bool Reader::decodeUnicodeEscapeSequence(Token& token,
742742 token,
743743 current);
744744 }
745+ ret_unicode = static_cast <unsigned int >(unicode);
745746 return true ;
746747}
747748
@@ -756,7 +757,7 @@ Reader::addError(const std::string& message, Token& token, Location extra) {
756757}
757758
758759bool Reader::recoverFromError (TokenType skipUntilToken) {
759- int errorCount = int ( errors_.size () );
760+ size_t const errorCount = errors_.size ();
760761 Token skip;
761762 for (;;) {
762763 if (!readToken (skip))
@@ -851,7 +852,7 @@ std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
851852}
852853
853854bool Reader::pushError (const Value& value, const std::string& message) {
854- size_t length = end_ - begin_;
855+ ptrdiff_t const length = end_ - begin_;
855856 if (value.getOffsetStart () > length
856857 || value.getOffsetLimit () > length)
857858 return false ;
@@ -868,7 +869,7 @@ bool Reader::pushError(const Value& value, const std::string& message) {
868869}
869870
870871bool 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_;
872873 if (value.getOffsetStart () > length
873874 || value.getOffsetLimit () > length
874875 || extra.getOffsetLimit () > length)
@@ -918,8 +919,8 @@ class OurReader {
918919 typedef char Char;
919920 typedef const Char* Location;
920921 struct StructuredError {
921- size_t offset_start;
922- size_t offset_limit;
922+ ptrdiff_t offset_start;
923+ ptrdiff_t offset_limit;
923924 std::string message;
924925 };
925926
@@ -1560,7 +1561,7 @@ bool OurReader::decodeNumber(Token& token, Value& decoded) {
15601561 Char c = *current++;
15611562 if (c < ' 0' || c > ' 9' )
15621563 return decodeDouble (token, decoded);
1563- Value::UInt digit (c - ' 0' );
1564+ Value::UInt digit (static_cast <Value::UInt>( c - ' 0' ) );
15641565 if (value >= threshold) {
15651566 // We've hit or exceeded the max value divided by 10 (rounded down). If
15661567 // 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) {
15961597 double value = 0 ;
15971598 const int bufferSize = 32 ;
15981599 int count;
1599- int length = int ( token.end_ - token.start_ ) ;
1600+ ptrdiff_t const length = token.end_ - token.start_ ;
16001601
16011602 // Sanity check to avoid buffer overflow exploits.
16021603 if (length < 0 ) {
16031604 return addError (" Unable to parse token length" , token);
16041605 }
1606+ size_t const ulength = static_cast <size_t >(length);
16051607
16061608 // Avoid using a string constant for the format control string given to
16071609 // 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) {
16121614
16131615 if (length <= bufferSize) {
16141616 Char buffer[bufferSize + 1 ];
1615- memcpy (buffer, token.start_ , length );
1617+ memcpy (buffer, token.start_ , ulength );
16161618 buffer[length] = 0 ;
16171619 count = sscanf (buffer, format, &value);
16181620 } else {
@@ -1640,7 +1642,7 @@ bool OurReader::decodeString(Token& token) {
16401642}
16411643
16421644bool 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 ) );
16441646 Location current = token.start_ + 1 ; // skip '"'
16451647 Location end = token.end_ - 1 ; // do not include '"'
16461648 while (current != end) {
@@ -1724,13 +1726,13 @@ bool OurReader::decodeUnicodeCodePoint(Token& token,
17241726bool OurReader::decodeUnicodeEscapeSequence (Token& token,
17251727 Location& current,
17261728 Location end,
1727- unsigned int & unicode ) {
1729+ unsigned int & ret_unicode ) {
17281730 if (end - current < 4 )
17291731 return addError (
17301732 " Bad unicode escape sequence in string: four digits expected." ,
17311733 token,
17321734 current);
1733- unicode = 0 ;
1735+ int unicode = 0 ;
17341736 for (int index = 0 ; index < 4 ; ++index) {
17351737 Char c = *current++;
17361738 unicode *= 16 ;
@@ -1746,6 +1748,7 @@ bool OurReader::decodeUnicodeEscapeSequence(Token& token,
17461748 token,
17471749 current);
17481750 }
1751+ ret_unicode = static_cast <unsigned int >(unicode);
17491752 return true ;
17501753}
17511754
@@ -1760,7 +1763,7 @@ OurReader::addError(const std::string& message, Token& token, Location extra) {
17601763}
17611764
17621765bool OurReader::recoverFromError (TokenType skipUntilToken) {
1763- int errorCount = int ( errors_.size () );
1766+ size_t errorCount = errors_.size ();
17641767 Token skip;
17651768 for (;;) {
17661769 if (!readToken (skip))
@@ -1850,7 +1853,7 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18501853}
18511854
18521855bool OurReader::pushError (const Value& value, const std::string& message) {
1853- size_t length = end_ - begin_;
1856+ ptrdiff_t length = end_ - begin_;
18541857 if (value.getOffsetStart () > length
18551858 || value.getOffsetLimit () > length)
18561859 return false ;
@@ -1867,7 +1870,7 @@ bool OurReader::pushError(const Value& value, const std::string& message) {
18671870}
18681871
18691872bool OurReader::pushError (const Value& value, const std::string& message, const Value& extra) {
1870- size_t length = end_ - begin_;
1873+ ptrdiff_t length = end_ - begin_;
18711874 if (value.getOffsetStart () > length
18721875 || value.getOffsetLimit () > length
18731876 || extra.getOffsetLimit () > length)
0 commit comments