From 3c427645632ac4d79ce441212631eea40d584c76 Mon Sep 17 00:00:00 2001 From: Mark Roszko Date: Sun, 22 Feb 2015 18:56:38 -0500 Subject: [PATCH] Fix snprintf usage. --- eeschema/sch_item_struct.cpp | 10 ++++------ lib_dxf/libdxfrw.cpp | 2 +- scripting/python_scripting.cpp | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_item_struct.cpp b/eeschema/sch_item_struct.cpp index 9a2cda7810..047d5c8699 100644 --- a/eeschema/sch_item_struct.cpp +++ b/eeschema/sch_item_struct.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -112,8 +112,7 @@ std::string SCH_ITEM::FormatInternalUnits( int aValue ) if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 ) { - // printf( "f: " ); - len = snprintf( buf, 49, "%.10f", engUnits ); + len = snprintf( buf, sizeof(buf), "%.10f", engUnits ); while( --len > 0 && buf[len] == '0' ) buf[len] = '\0'; @@ -122,8 +121,7 @@ std::string SCH_ITEM::FormatInternalUnits( int aValue ) } else { - // printf( "g: " ); - len = snprintf( buf, 49, "%.10g", engUnits ); + len = snprintf( buf, sizeof(buf), "%.10g", engUnits ); } return std::string( buf, len ); @@ -135,7 +133,7 @@ std::string SCH_ITEM::FormatAngle( double aAngle ) char temp[50]; int len; - len = snprintf( temp, 49, "%.10g", aAngle / 10.0 ); + len = snprintf( temp, sizeof(temp), "%.10g", aAngle / 10.0 ); return std::string( temp, len ); } diff --git a/lib_dxf/libdxfrw.cpp b/lib_dxf/libdxfrw.cpp index 2390b38bed..ce4c7a532a 100644 --- a/lib_dxf/libdxfrw.cpp +++ b/lib_dxf/libdxfrw.cpp @@ -3818,7 +3818,7 @@ std::string dxfRW::toHexStr( int n ) { #if defined(__APPLE__) char buffer[9] = { '\0' }; - snprintf( buffer, 9, "%X", n ); + snprintf( buffer, sizeof(buffer), "%X", n ); return std::string( buffer ); #else std::ostringstream Convert; diff --git a/scripting/python_scripting.cpp b/scripting/python_scripting.cpp index 15f0d6c156..0f8072e6ff 100644 --- a/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -144,7 +144,7 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) // Make sure that that the correct version of wxPython is loaded. In systems where there // are different versions of wxPython installed this can lead to select wrong wxPython // version being selected. - snprintf( cmd, 1023, "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); + snprintf( cmd, sizeof(cmd), "import wxversion; wxversion.select('%s')", WXPYTHON_VERSION ); PyRun_SimpleString( cmd ); // Load the wxPython core API. Imports the wx._core_ module and sets a @@ -168,7 +168,7 @@ bool pcbnewInitPythonScripting( const char * aUserPluginsPath ) { char cmd[1024]; PyLOCK lock; - sprintf( cmd, "import sys, traceback\n" + snprintf( cmd, sizeof(cmd), "import sys, traceback\n" "sys.path.append(\".\")\n" "import pcbnew\n" "pcbnew.LoadPlugins(\"%s\")", aUserPluginsPath );