From a44cffb342d3ff239b61f61257793488e249ac3d Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Wed, 9 May 2007 19:35:15 +0000 Subject: [PATCH] Fixed compilation warnings. Added -Wall to linux-gcc compilation. JSON_ASSERT_MESSAGE now throws exception (but JSON_ASSERT does not). --- SConstruct | 2 +- include/json/value.h | 2 +- src/jsontestrunner/main.cpp | 4 ++-- src/lib_json/json_value.cpp | 35 ++++++++++++++++++----------------- src/lib_json/json_writer.cpp | 6 +++--- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/SConstruct b/SConstruct index e820659..b4cba59 100644 --- a/SConstruct +++ b/SConstruct @@ -76,7 +76,7 @@ elif platform == 'mingw': env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] ) elif platform == 'linux-gcc': env.Tool( 'default' ) - env.Append( LIBS = ['pthread'] ) + env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" ) else: print "UNSUPPORTED PLATFORM." env.Exit(1) diff --git a/include/json/value.h b/include/json/value.h index de09d5f..480f433 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -518,7 +518,7 @@ namespace Json { class ValueAllocator { public: - enum { unknown = -1 }; + enum { unknown = (unsigned)-1 }; virtual ~ValueAllocator(); diff --git a/src/jsontestrunner/main.cpp b/src/jsontestrunner/main.cpp index 98cd8fd..1d8b303 100644 --- a/src/jsontestrunner/main.cpp +++ b/src/jsontestrunner/main.cpp @@ -13,12 +13,12 @@ readInputTestFile( const char *path ) if ( !file ) return std::string(""); fseek( file, 0, SEEK_END ); - int size = ftell( file ); + long size = ftell( file ); fseek( file, 0, SEEK_SET ); std::string text; char *buffer = new char[size+1]; buffer[size] = 0; - if ( fread( buffer, 1, size, file ) == size ) + if ( fread( buffer, 1, size, file ) == (unsigned long)size ) text = buffer; fclose( file ); delete[] buffer; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 329b634..bc4ba3d 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "assert.h" #ifdef JSON_USE_CPPTL # include @@ -13,7 +14,7 @@ #define JSON_ASSERT_UNREACHABLE assert( false ) #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw -#define JSON_ASSERT_MESSAGE( condition, message ) assert( condition && message ); // @todo <= change this into an exception throw +#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message ); namespace Json { @@ -265,8 +266,8 @@ Value::CZString::isStaticString() const */ Value::Value( ValueType type ) : type_( type ) - , comments_( 0 ) , allocated_( 0 ) + , comments_( 0 ) # ifdef JSON_VALUE_USE_INTERNAL_MAP , itemIsUsed_( 0 ) #endif @@ -680,7 +681,7 @@ Value::asString() const case realValue: case arrayValue: case objectValue: - JSON_ASSERT( "Type is not convertible to double" && false ); + JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" ); default: JSON_ASSERT_UNREACHABLE; } @@ -705,17 +706,17 @@ Value::asInt() const case intValue: return value_.int_; case uintValue: - JSON_ASSERT( value_.uint_ < maxInt && "integer out of signed integer range" ); + JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" ); return value_.uint_; case realValue: - JSON_ASSERT( value_.real_ >= minInt && value_.real_ <= maxInt && "Real out of signed integer range" ); + JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" ); return Int( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: - JSON_ASSERT( "Type is not convertible to double" && false ); + JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" ); default: JSON_ASSERT_UNREACHABLE; } @@ -730,19 +731,19 @@ Value::asUInt() const case nullValue: return 0; case intValue: - JSON_ASSERT( value_.int_ >= 0 && "Negative integer can not be converted to unsigned integer" ); + JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" ); return value_.int_; case uintValue: return value_.uint_; case realValue: - JSON_ASSERT( value_.real_ >= 0 && value_.real_ <= maxUInt && "Real out of unsigned integer range" ); + JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" ); return UInt( value_.real_ ); case booleanValue: return value_.bool_ ? 1 : 0; case stringValue: case arrayValue: case objectValue: - JSON_ASSERT( "Type is not convertible to double" && false ); + JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" ); default: JSON_ASSERT_UNREACHABLE; } @@ -767,7 +768,7 @@ Value::asDouble() const case stringValue: case arrayValue: case objectValue: - JSON_ASSERT( "Type is not convertible to double" && false ); + JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" ); default: JSON_ASSERT_UNREACHABLE; } @@ -816,7 +817,7 @@ Value::isConvertibleTo( ValueType other ) const || other == booleanValue; case uintValue: return ( other == nullValue && value_.uint_ == 0 ) - || ( other == intValue && value_.uint_ <= maxInt ) + || ( other == intValue && value_.uint_ <= (unsigned)maxInt ) || other == uintValue || other == realValue || other == stringValue @@ -1499,22 +1500,22 @@ PathArgument::PathArgument() PathArgument::PathArgument( Value::UInt index ) - : kind_( kindIndex ) - , index_( index ) + : index_( index ) + , kind_( kindIndex ) { } PathArgument::PathArgument( const char *key ) - : kind_( kindKey ) - , key_( key ) + : key_( key ) + , kind_( kindKey ) { } PathArgument::PathArgument( const std::string &key ) - : kind_( kindKey ) - , key_( key.c_str() ) + : key_( key.c_str() ) + , kind_( kindKey ) { } diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 8af01f3..7485e5a 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -290,7 +290,7 @@ StyledWriter::writeValue( const Value &value ) void StyledWriter::writeArrayValue( const Value &value ) { - int size = value.size(); + unsigned size = value.size(); if ( size == 0 ) pushValue( "[]" ); else @@ -301,7 +301,7 @@ StyledWriter::writeArrayValue( const Value &value ) writeWithIndent( "[" ); indent(); bool hasChildValue = !childValues_.empty(); - int index =0; + unsigned index =0; while ( true ) { const Value &childValue = value[index]; @@ -328,7 +328,7 @@ StyledWriter::writeArrayValue( const Value &value ) { assert( childValues_.size() == size ); document_ += "[ "; - for ( int index =0; index < size; ++index ) + for ( unsigned index =0; index < size; ++index ) { if ( index > 0 ) document_ += ", ";