Skip to content

Commit d261880

Browse files
committed
Fixed some snprintf-related build breakages in Visual Studio.
1 parent 36400ac commit d261880

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/jsontestrunner/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ static std::string
1919
normalizeFloatingPointStr( double value )
2020
{
2121
char buffer[32];
22+
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
23+
sprintf_s( buffer, sizeof(buffer), "%.16g", value );
24+
#else
2225
snprintf( buffer, sizeof(buffer), "%.16g", value );
26+
#endif
2327
buffer[sizeof(buffer)-1] = 0;
2428
std::string s( buffer );
2529
std::string::size_type index = s.find_last_of( "eE" );
@@ -89,7 +93,11 @@ printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
8993
for ( int index =0; index < size; ++index )
9094
{
9195
static char buffer[16];
96+
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
97+
sprintf_s( buffer, sizeof(buffer), "[%d]", index );
98+
#else
9299
snprintf( buffer, sizeof(buffer), "[%d]", index );
100+
#endif
93101
printValueTree( fout, value[index], path + buffer );
94102
}
95103
}

src/lib_json/json_reader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,11 @@ Reader::getLocationLineAndColumn( Location location ) const
868868
int line, column;
869869
getLocationLineAndColumn( location, line, column );
870870
char buffer[18+16+16+1];
871+
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
872+
sprintf_s(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
873+
#else
871874
snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
875+
#endif
872876
return buffer;
873877
}
874878

0 commit comments

Comments
 (0)