Convert additional sprintf to snprintf

This commit is contained in:
Chris Morgan 2023-01-28 20:55:11 -05:00 committed by Mark Roszko
parent 3d52115ae7
commit ce06171561
5 changed files with 31 additions and 31 deletions

View File

@ -305,22 +305,22 @@ bool GENDRILL_WRITER_BASE::genDrillMapFile( const wxString& aFullFileName, PLOT_
plotter->SetCurrentLineWidth( -1 ); plotter->SetCurrentLineWidth( -1 );
// List the diameter of each drill in mm and inches. // List the diameter of each drill in mm and inches.
sprintf( line, "%3.3fmm / %2.4f\" ", diameter_in_mm( tool.m_Diameter ), snprintf( line, sizeof(line), "%3.3fmm / %2.4f\" ", diameter_in_mm( tool.m_Diameter ),
diameter_in_inches( tool.m_Diameter ) ); diameter_in_inches( tool.m_Diameter ) );
msg = FROM_UTF8( line ); msg = FROM_UTF8( line );
// Now list how many holes and ovals are associated with each drill. // Now list how many holes and ovals are associated with each drill.
if( ( tool.m_TotalCount == 1 ) && ( tool.m_OvalCount == 0 ) ) if( ( tool.m_TotalCount == 1 ) && ( tool.m_OvalCount == 0 ) )
sprintf( line, "(1 hole)" ); snprintf( line, sizeof(line), "(1 hole)" );
else if( tool.m_TotalCount == 1 ) // && ( toolm_OvalCount == 1 ) else if( tool.m_TotalCount == 1 ) // && ( toolm_OvalCount == 1 )
sprintf( line, "(1 slot)" ); snprintf( line, sizeof(line), "(1 slot)" );
else if( tool.m_OvalCount == 0 ) else if( tool.m_OvalCount == 0 )
sprintf( line, "(%d holes)", tool.m_TotalCount ); snprintf( line, sizeof(line), "(%d holes)", tool.m_TotalCount );
else if( tool.m_OvalCount == 1 ) else if( tool.m_OvalCount == 1 )
sprintf( line, "(%d holes + 1 slot)", tool.m_TotalCount - 1 ); snprintf( line, sizeof(line), "(%d holes + 1 slot)", tool.m_TotalCount - 1 );
else // if ( toolm_OvalCount > 1 ) else // if ( toolm_OvalCount > 1 )
sprintf( line, "(%d holes + %d slots)", tool.m_TotalCount - tool.m_OvalCount, snprintf( line, sizeof(line), "(%d holes + %d slots)", tool.m_TotalCount - tool.m_OvalCount,
tool.m_OvalCount ); tool.m_OvalCount );
msg += FROM_UTF8( line ); msg += FROM_UTF8( line );

View File

@ -167,7 +167,7 @@ std::string PLACE_FILE_EXPORTER::GenPositionData()
wxChar csv_sep = ','; wxChar csv_sep = ',';
// Set first line:; // Set first line:;
sprintf( line, "Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n", snprintf( line, sizeof(line), "Ref%cVal%cPackage%cPosX%cPosY%cRot%cSide\n",
csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep ); csv_sep, csv_sep, csv_sep, csv_sep, csv_sep, csv_sep );
buffer += line; buffer += line;
@ -211,12 +211,12 @@ std::string PLACE_FILE_EXPORTER::GenPositionData()
else else
{ {
// Write file header // Write file header
sprintf( line, "### Footprint positions - created on %s ###\n", TO_UTF8( DateAndTime() ) ); snprintf( line, sizeof(line), "### Footprint positions - created on %s ###\n", TO_UTF8( DateAndTime() ) );
buffer += line; buffer += line;
wxString Title = GetBuildVersion(); wxString Title = GetBuildVersion();
sprintf( line, "### Printed by KiCad version %s\n", TO_UTF8( Title ) ); snprintf( line, sizeof(line), "### Printed by KiCad version %s\n", TO_UTF8( Title ) );
buffer += line; buffer += line;
buffer += unit_text; buffer += unit_text;
@ -233,7 +233,7 @@ std::string PLACE_FILE_EXPORTER::GenPositionData()
buffer += "\n"; buffer += "\n";
sprintf(line, "%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n", snprintf(line, sizeof(line), "%-*s %-*s %-*s %9.9s %9.9s %8.8s %s\n",
int(lenRefText), "# Ref", int(lenRefText), "# Ref",
int(lenValText), "Val", int(lenValText), "Val",
int(lenPkgText), "Package", int(lenPkgText), "Package",
@ -258,7 +258,7 @@ std::string PLACE_FILE_EXPORTER::GenPositionData()
ref.Replace( wxT( " " ), wxT( "_" ) ); ref.Replace( wxT( " " ), wxT( "_" ) );
val.Replace( wxT( " " ), wxT( "_" ) ); val.Replace( wxT( " " ), wxT( "_" ) );
pkg.Replace( wxT( " " ), wxT( "_" ) ); pkg.Replace( wxT( " " ), wxT( "_" ) );
sprintf(line, "%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n", snprintf(line, sizeof(line), "%-*s %-*s %-*s %9.4f %9.4f %8.4f %s\n",
lenRefText, TO_UTF8( ref ), lenRefText, TO_UTF8( ref ),
lenValText, TO_UTF8( val ), lenValText, TO_UTF8( val ),
lenPkgText, TO_UTF8( pkg ), lenPkgText, TO_UTF8( pkg ),
@ -293,11 +293,11 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
// Generate header file comments.) // Generate header file comments.)
char line[1024]; char line[1024];
sprintf( line, "## Footprint report - date %s\n", TO_UTF8( DateAndTime() ) ); snprintf( line, sizeof(line), "## Footprint report - date %s\n", TO_UTF8( DateAndTime() ) );
buffer += line; buffer += line;
wxString Title = GetBuildVersion(); wxString Title = GetBuildVersion();
sprintf( line, "## Created by KiCad version %s\n", TO_UTF8( Title ) ); snprintf( line, sizeof(line), "## Created by KiCad version %s\n", TO_UTF8( Title ) );
buffer += line; buffer += line;
buffer += unit_text; buffer += unit_text;
@ -308,11 +308,11 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
buffer += "\n$BOARD\n"; buffer += "\n$BOARD\n";
sprintf( line, "upper_left_corner %9.6f %9.6f\n", snprintf( line, sizeof(line), "upper_left_corner %9.6f %9.6f\n",
bbbox.GetX() * conv_unit, bbbox.GetY() * conv_unit ); bbbox.GetX() * conv_unit, bbbox.GetY() * conv_unit );
buffer += line; buffer += line;
sprintf( line, "lower_right_corner %9.6f %9.6f\n", snprintf( line, sizeof(line), "lower_right_corner %9.6f %9.6f\n",
bbbox.GetRight() * conv_unit, bbbox.GetBottom() * conv_unit ); bbbox.GetRight() * conv_unit, bbbox.GetBottom() * conv_unit );
buffer += line; buffer += line;
@ -333,12 +333,12 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
{ {
wxString ref = footprint->Reference().GetShownText(); wxString ref = footprint->Reference().GetShownText();
sprintf( line, "$MODULE %s\n", TO_UTF8( ref ) ); snprintf( line, sizeof(line), "$MODULE %s\n", TO_UTF8( ref ) );
buffer += line; buffer += line;
sprintf( line, "reference %s\n", TO_UTF8( ref ) ); snprintf( line, sizeof(line), "reference %s\n", TO_UTF8( ref ) );
sprintf( line, "value %s\n", EscapedUTF8( footprint->Value().GetShownText() ).c_str() ); snprintf( line, sizeof(line), "value %s\n", EscapedUTF8( footprint->Value().GetShownText() ).c_str() );
sprintf( line, "footprint %s\n", footprint->GetFPID().Format().c_str() ); snprintf( line, sizeof(line), "footprint %s\n", footprint->GetFPID().Format().c_str() );
buffer += line; buffer += line;
buffer += "attribut"; buffer += "attribut";
@ -357,7 +357,7 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
VECTOR2I footprint_pos = footprint->GetPosition(); VECTOR2I footprint_pos = footprint->GetPosition();
footprint_pos -= m_place_Offset; footprint_pos -= m_place_Offset;
sprintf( line, "position %9.6f %9.6f orientation %.2f\n", snprintf( line, sizeof(line), "position %9.6f %9.6f orientation %.2f\n",
footprint_pos.x * conv_unit, footprint_pos.x * conv_unit,
footprint_pos.y * conv_unit, footprint_pos.y * conv_unit,
footprint->GetOrientation().AsDegrees() ); footprint->GetOrientation().AsDegrees() );
@ -383,7 +383,7 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
for( PAD* pad : sortedPads ) for( PAD* pad : sortedPads )
{ {
sprintf( line, "$PAD \"%s\"\n", TO_UTF8( pad->GetNumber() ) ); snprintf( line, sizeof(line), "$PAD \"%s\"\n", TO_UTF8( pad->GetNumber() ) );
buffer += line; buffer += line;
int layer = 0; int layer = 0;
@ -395,12 +395,12 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
layer |= 2; layer |= 2;
static const char* layer_name[4] = { "nocopper", "back", "front", "both" }; static const char* layer_name[4] = { "nocopper", "back", "front", "both" };
sprintf( line, "Shape %s Layer %s\n", snprintf( line, sizeof(line), "Shape %s Layer %s\n",
TO_UTF8( pad->ShowPadShape() ), TO_UTF8( pad->ShowPadShape() ),
layer_name[layer] ); layer_name[layer] );
buffer += line; buffer += line;
sprintf( line, "position %9.6f %9.6f size %9.6f %9.6f orientation %.2f\n", snprintf( line, sizeof(line), "position %9.6f %9.6f size %9.6f %9.6f orientation %.2f\n",
pad->GetPos0().x * conv_unit, pad->GetPos0().x * conv_unit,
pad->GetPos0().y * conv_unit, pad->GetPos0().y * conv_unit,
pad->GetSize().x * conv_unit, pad->GetSize().x * conv_unit,
@ -408,10 +408,10 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
( pad->GetOrientation() - footprint->GetOrientation() ).AsDegrees() ); ( pad->GetOrientation() - footprint->GetOrientation() ).AsDegrees() );
buffer += line; buffer += line;
sprintf( line, "drill %9.6f\n", pad->GetDrillSize().x * conv_unit ); snprintf( line, sizeof(line), "drill %9.6f\n", pad->GetDrillSize().x * conv_unit );
buffer += line; buffer += line;
sprintf( line, "shape_offset %9.6f %9.6f\n", snprintf( line, sizeof(line), "shape_offset %9.6f %9.6f\n",
pad->GetOffset().x * conv_unit, pad->GetOffset().x * conv_unit,
pad->GetOffset().y * conv_unit ); pad->GetOffset().y * conv_unit );
buffer += line; buffer += line;
@ -419,7 +419,7 @@ std::string PLACE_FILE_EXPORTER::GenReportData()
buffer += "$EndPAD\n"; buffer += "$EndPAD\n";
} }
sprintf( line, "$EndMODULE %s\n\n", TO_UTF8( ref ) ); snprintf( line, sizeof(line), "$EndMODULE %s\n\n", TO_UTF8( ref ) );
buffer += line; buffer += line;
} }

View File

@ -722,8 +722,8 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
char ybuf[30]; char ybuf[30];
// EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet. // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
sprintf( xbuf, "%d", GetPageSizeIU().x ); snprintf( xbuf, sizeof(xbuf), "%d", GetPageSizeIU().x );
sprintf( ybuf, "%d", GetPageSizeIU().y ); snprintf( ybuf, sizeof(ybuf), "%d", GetPageSizeIU().y );
props["page_width"] = xbuf; props["page_width"] = xbuf;
props["page_height"] = ybuf; props["page_height"] = ybuf;

View File

@ -3111,7 +3111,7 @@ void LP_CACHE::LoadModules( LINE_READER* aReader )
std::string newName = footprintName; std::string newName = footprintName;
newName += "_v"; newName += "_v";
sprintf( buf, "%d", version++ ); snprintf( buf, sizeof(buf), "%d", version++ );
newName += buf; newName += buf;
it = m_footprints.find( newName ); it = m_footprints.find( newName );

View File

@ -1255,8 +1255,8 @@ int PCB_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName )
char ybuf[30]; char ybuf[30];
// EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet. // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
sprintf( xbuf, "%d", editFrame->GetPageSizeIU().x ); snprintf( xbuf, sizeof(xbuf), "%d", editFrame->GetPageSizeIU().x );
sprintf( ybuf, "%d", editFrame->GetPageSizeIU().y ); snprintf( ybuf, sizeof(ybuf), "%d", editFrame->GetPageSizeIU().y );
props["page_width"] = xbuf; props["page_width"] = xbuf;
props["page_height"] = ybuf; props["page_height"] = ybuf;