Coverity: tackled a few CIDs (#470)

This commit is contained in:
tomcw
2018-08-12 12:48:08 +01:00
parent 74c0ca2cde
commit 396c55d8a3
4 changed files with 60 additions and 32 deletions
+16 -3
View File
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "StdAfx.h"
#include "Applewin.h"
#include "Frame.h" // g_hFrameWindow
#include "Memory.h"
#include "ParallelPrinter.h"
#include "Registry.h"
@@ -234,14 +235,26 @@ char* Printer_GetFilename()
void Printer_SetFilename(char* prtFilename)
{
if(*prtFilename)
if (*prtFilename)
{
strcpy(g_szPrintFilename, (const char *) prtFilename);
}
else //No registry entry is available
{
_tcsncpy(g_szPrintFilename, g_sProgramDir, MAX_PATH);
g_szPrintFilename[MAX_PATH - 1] = 0;
_tcsncat(g_szPrintFilename, _T(DEFAULT_PRINT_FILENAME), MAX_PATH);
RegSaveString(TEXT("Configuration"),REGVALUE_PRINTER_FILENAME,1,g_szPrintFilename);
// NB. _tcsncat_s() terminates program if buffer is too small! So continue to use manual buffer check & _tcsncat()
int nLen = sizeof(g_szPrintFilename) - strlen(g_szPrintFilename) - (sizeof(DEFAULT_PRINT_FILENAME)-1) - 1;
if (nLen < 0)
{
MessageBox(g_hFrameWindow, "Printer - SetFilename(): folder too deep", "Warning", MB_ICONWARNING | MB_OK);
return;
}
_tcsncat(g_szPrintFilename, DEFAULT_PRINT_FILENAME, sizeof(DEFAULT_PRINT_FILENAME)-1);
RegSaveString(REG_CONFIG, REGVALUE_PRINTER_FILENAME, 1, g_szPrintFilename);
}
}