AppleWin/source/Log.cpp

63 lines
1.7 KiB
C++
Raw Normal View History

/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski, Nick Westgate
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Description: Log
*
* Author: Nick Westgate
*/
#include "StdAfx.h"
FILE* g_fh = NULL;
//---------------------------------------------------------------------------
void LogOutput(LPCTSTR format, ...)
{
2015-07-30 16:21:31 +00:00
TCHAR output[256];
2015-07-30 16:21:31 +00:00
va_list args;
va_start(args, format);
2015-07-30 16:21:31 +00:00
_vsntprintf(output, sizeof(output) - 1, format, args);
Fix the following errors reported by VS2017 Code Analysis. (#414) * Fix the following errors reported by VS2017 Code Analysis. applewin\source\applewin.cpp(761): warning C6385: Reading invalid data from '"Disk Image"': the readable size is '11' bytes, but '21' bytes may be read. applewin\source\debugger\debug.cpp(6624): warning C6386: Buffer overrun while writing to 'sName': the writable size is '31' bytes, but '32' bytes might be written. applewin\source\debugger\debugger_display.cpp(3715): warning C6053: The prior call to 'strncpy' might not zero-terminate string 'sText'. applewin\source\log.cpp(42): warning C6053: The prior call to '_vsnprintf' might not zero-terminate string 'output'. applewin\source\debugger\debug.cpp(2759): warning C6011: Dereferencing NULL pointer 'pFont'. applewin\source\debugger\debugger_symbols.cpp(243): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'pText'. applewin\source\diskimagehelper.cpp(1132): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'pszExt'. applewin\source\diskimagehelper.cpp(1141): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'szFilename'. applewin\source\parallelprinter.cpp(242): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'g_szPrintFilename'. The one about RegSetValue(), according to Microsoft https://msdn.microsoft.com/en-us/library/windows/desktop/ms724922(v=vs.85).aspx the last argument cbData is ignored, so I set it to 0, as in some cases was anyway wrong (see "DiskImage"). Signed-off-by: Andrea Odetti <mariofutire@gmail.com> * Use sizeof() rather than hardcoded value. Fix one more case on non terminated string. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
2018-02-24 15:24:37 +00:00
output[sizeof(output) - 1] = 0;
2015-07-30 16:21:31 +00:00
OutputDebugString(output);
}
//---------------------------------------------------------------------------
void LogFileOutput(LPCTSTR format, ...)
{
if (!g_fh)
return;
2015-07-30 16:21:31 +00:00
TCHAR output[256];
2015-07-30 16:21:31 +00:00
va_list args;
va_start(args, format);
2015-07-30 16:21:31 +00:00
_vsntprintf(output, sizeof(output) - 1, format, args);
Fix the following errors reported by VS2017 Code Analysis. (#414) * Fix the following errors reported by VS2017 Code Analysis. applewin\source\applewin.cpp(761): warning C6385: Reading invalid data from '"Disk Image"': the readable size is '11' bytes, but '21' bytes may be read. applewin\source\debugger\debug.cpp(6624): warning C6386: Buffer overrun while writing to 'sName': the writable size is '31' bytes, but '32' bytes might be written. applewin\source\debugger\debugger_display.cpp(3715): warning C6053: The prior call to 'strncpy' might not zero-terminate string 'sText'. applewin\source\log.cpp(42): warning C6053: The prior call to '_vsnprintf' might not zero-terminate string 'output'. applewin\source\debugger\debug.cpp(2759): warning C6011: Dereferencing NULL pointer 'pFont'. applewin\source\debugger\debugger_symbols.cpp(243): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'pText'. applewin\source\diskimagehelper.cpp(1132): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'pszExt'. applewin\source\diskimagehelper.cpp(1141): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'szFilename'. applewin\source\parallelprinter.cpp(242): warning C6053: The prior call to '_tcsncpy' might not zero-terminate string 'g_szPrintFilename'. The one about RegSetValue(), according to Microsoft https://msdn.microsoft.com/en-us/library/windows/desktop/ms724922(v=vs.85).aspx the last argument cbData is ignored, so I set it to 0, as in some cases was anyway wrong (see "DiskImage"). Signed-off-by: Andrea Odetti <mariofutire@gmail.com> * Use sizeof() rather than hardcoded value. Fix one more case on non terminated string. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
2018-02-24 15:24:37 +00:00
output[sizeof(output) - 1] = 0;
2015-07-30 16:21:31 +00:00
fprintf(g_fh, "%s", output);
}