Skip to content

Commit a44cffb

Browse files
committed
Fixed compilation warnings. Added -Wall to linux-gcc compilation. JSON_ASSERT_MESSAGE now throws exception (but JSON_ASSERT does not).
1 parent 842d64e commit a44cffb

5 files changed

Lines changed: 25 additions & 24 deletions

File tree

SConstruct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ elif platform == 'mingw':
7676
env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
7777
elif platform == 'linux-gcc':
7878
env.Tool( 'default' )
79-
env.Append( LIBS = ['pthread'] )
79+
env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
8080
else:
8181
print "UNSUPPORTED PLATFORM."
8282
env.Exit(1)

include/json/value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ namespace Json {
518518
class ValueAllocator
519519
{
520520
public:
521-
enum { unknown = -1 };
521+
enum { unknown = (unsigned)-1 };
522522

523523
virtual ~ValueAllocator();
524524

src/jsontestrunner/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ readInputTestFile( const char *path )
1313
if ( !file )
1414
return std::string("");
1515
fseek( file, 0, SEEK_END );
16-
int size = ftell( file );
16+
long size = ftell( file );
1717
fseek( file, 0, SEEK_SET );
1818
std::string text;
1919
char *buffer = new char[size+1];
2020
buffer[size] = 0;
21-
if ( fread( buffer, 1, size, file ) == size )
21+
if ( fread( buffer, 1, size, file ) == (unsigned long)size )
2222
text = buffer;
2323
fclose( file );
2424
delete[] buffer;

src/lib_json/json_value.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <json/value.h>
33
#include <json/writer.h>
44
#include <utility>
5+
#include <stdexcept>
56
#include "assert.h"
67
#ifdef JSON_USE_CPPTL
78
# include <cpptl/conststring.h>
@@ -13,7 +14,7 @@
1314

1415
#define JSON_ASSERT_UNREACHABLE assert( false )
1516
#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
16-
#define JSON_ASSERT_MESSAGE( condition, message ) assert( condition && message ); // @todo <= change this into an exception throw
17+
#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
1718

1819
namespace Json {
1920

@@ -265,8 +266,8 @@ Value::CZString::isStaticString() const
265266
*/
266267
Value::Value( ValueType type )
267268
: type_( type )
268-
, comments_( 0 )
269269
, allocated_( 0 )
270+
, comments_( 0 )
270271
# ifdef JSON_VALUE_USE_INTERNAL_MAP
271272
, itemIsUsed_( 0 )
272273
#endif
@@ -680,7 +681,7 @@ Value::asString() const
680681
case realValue:
681682
case arrayValue:
682683
case objectValue:
683-
JSON_ASSERT( "Type is not convertible to double" && false );
684+
JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" );
684685
default:
685686
JSON_ASSERT_UNREACHABLE;
686687
}
@@ -705,17 +706,17 @@ Value::asInt() const
705706
case intValue:
706707
return value_.int_;
707708
case uintValue:
708-
JSON_ASSERT( value_.uint_ < maxInt && "integer out of signed integer range" );
709+
JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" );
709710
return value_.uint_;
710711
case realValue:
711-
JSON_ASSERT( value_.real_ >= minInt && value_.real_ <= maxInt && "Real out of signed integer range" );
712+
JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" );
712713
return Int( value_.real_ );
713714
case booleanValue:
714715
return value_.bool_ ? 1 : 0;
715716
case stringValue:
716717
case arrayValue:
717718
case objectValue:
718-
JSON_ASSERT( "Type is not convertible to double" && false );
719+
JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" );
719720
default:
720721
JSON_ASSERT_UNREACHABLE;
721722
}
@@ -730,19 +731,19 @@ Value::asUInt() const
730731
case nullValue:
731732
return 0;
732733
case intValue:
733-
JSON_ASSERT( value_.int_ >= 0 && "Negative integer can not be converted to unsigned integer" );
734+
JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" );
734735
return value_.int_;
735736
case uintValue:
736737
return value_.uint_;
737738
case realValue:
738-
JSON_ASSERT( value_.real_ >= 0 && value_.real_ <= maxUInt && "Real out of unsigned integer range" );
739+
JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" );
739740
return UInt( value_.real_ );
740741
case booleanValue:
741742
return value_.bool_ ? 1 : 0;
742743
case stringValue:
743744
case arrayValue:
744745
case objectValue:
745-
JSON_ASSERT( "Type is not convertible to double" && false );
746+
JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" );
746747
default:
747748
JSON_ASSERT_UNREACHABLE;
748749
}
@@ -767,7 +768,7 @@ Value::asDouble() const
767768
case stringValue:
768769
case arrayValue:
769770
case objectValue:
770-
JSON_ASSERT( "Type is not convertible to double" && false );
771+
JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" );
771772
default:
772773
JSON_ASSERT_UNREACHABLE;
773774
}
@@ -816,7 +817,7 @@ Value::isConvertibleTo( ValueType other ) const
816817
|| other == booleanValue;
817818
case uintValue:
818819
return ( other == nullValue && value_.uint_ == 0 )
819-
|| ( other == intValue && value_.uint_ <= maxInt )
820+
|| ( other == intValue && value_.uint_ <= (unsigned)maxInt )
820821
|| other == uintValue
821822
|| other == realValue
822823
|| other == stringValue
@@ -1499,22 +1500,22 @@ PathArgument::PathArgument()
14991500

15001501

15011502
PathArgument::PathArgument( Value::UInt index )
1502-
: kind_( kindIndex )
1503-
, index_( index )
1503+
: index_( index )
1504+
, kind_( kindIndex )
15041505
{
15051506
}
15061507

15071508

15081509
PathArgument::PathArgument( const char *key )
1509-
: kind_( kindKey )
1510-
, key_( key )
1510+
: key_( key )
1511+
, kind_( kindKey )
15111512
{
15121513
}
15131514

15141515

15151516
PathArgument::PathArgument( const std::string &key )
1516-
: kind_( kindKey )
1517-
, key_( key.c_str() )
1517+
: key_( key.c_str() )
1518+
, kind_( kindKey )
15181519
{
15191520
}
15201521

src/lib_json/json_writer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ StyledWriter::writeValue( const Value &value )
290290
void
291291
StyledWriter::writeArrayValue( const Value &value )
292292
{
293-
int size = value.size();
293+
unsigned size = value.size();
294294
if ( size == 0 )
295295
pushValue( "[]" );
296296
else
@@ -301,7 +301,7 @@ StyledWriter::writeArrayValue( const Value &value )
301301
writeWithIndent( "[" );
302302
indent();
303303
bool hasChildValue = !childValues_.empty();
304-
int index =0;
304+
unsigned index =0;
305305
while ( true )
306306
{
307307
const Value &childValue = value[index];
@@ -328,7 +328,7 @@ StyledWriter::writeArrayValue( const Value &value )
328328
{
329329
assert( childValues_.size() == size );
330330
document_ += "[ ";
331-
for ( int index =0; index < size; ++index )
331+
for ( unsigned index =0; index < size; ++index )
332332
{
333333
if ( index > 0 )
334334
document_ += ", ";

0 commit comments

Comments
 (0)