Skip to content

Commit 42d918b

Browse files
committed
Switched away from sprintf, which is prone to buffer overflows.
Most reasonable platforms have this function. If you're here because this broke the build for you, consider adding an ifdef for your platform and using sprintf there (but not on other platforms).
1 parent 700b380 commit 42d918b

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib_json/json_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ Reader::getLocationLineAndColumn( Location location ) const
868868
int line, column;
869869
getLocationLineAndColumn( location, line, column );
870870
char buffer[18+16+16+1];
871-
sprintf( buffer, "Line %d, Column %d", line, column );
871+
snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
872872
return buffer;
873873
}
874874

src/lib_json/json_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ std::string valueToString( double value )
7777
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning.
7878
sprintf_s(buffer, sizeof(buffer), "%#.16g", value);
7979
#else
80-
sprintf(buffer, "%#.16g", value);
80+
snprintf(buffer, sizeof(buffer), "%#.16g", value);
8181
#endif
8282
char* ch = buffer + strlen(buffer) - 1;
8383
if (*ch != '0') return buffer; // nothing to truncate, so save time

0 commit comments

Comments
 (0)