diff --git a/common/base_units.cpp b/common/base_units.cpp index f8e1c55941..db568d2fdf 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -226,22 +226,17 @@ wxString StringFromValue( EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, if( value_to_print != 0.0 && fabs( value_to_print ) <= 0.0001 ) { - len = sprintf( buf, "%.10f", value_to_print ); + len = snprintf( buf, sizeof( buf ) - 1, "%.10f", value_to_print ); while( --len > 0 && buf[len] == '0' ) buf[len] = '\0'; - if( buf[len]=='.' || buf[len]==',' ) + if( len >= 0 && ( buf[len]=='.' || buf[len]==',' ) ) buf[len] = '\0'; - else - ++len; } else { - if( aUnits == EDA_UNITS::MILS ) - len = sprintf( buf, "%.7g", value_to_print ); - else - len = sprintf( buf, "%.10g", value_to_print ); + snprintf( buf, sizeof( buf ) - 1, "%.10g", value_to_print ); } wxString stringValue( buf, wxConvUTF8 );