Static Code Analysis: check return of remove function and display message when it fails.

This commit is contained in:
Mounir IDRASSI 2015-02-08 23:46:47 +01:00
parent d5f34ad49d
commit 5f252f2c50

View File

@ -270,7 +270,8 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
char tmpstr [1000];
StringCbPrintfA (tmpstr, sizeof(tmpstr), "File not found:\n\n'%s'", szTmpFilePath);
remove (outputFile);
if (remove (outputFile))
StringCbCatA (tmpstr, sizeof(tmpstr), "\nFailed also to delete package file");
PkgError (tmpstr);
goto err;
}
@ -287,7 +288,10 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
if (buffer == NULL)
{
PkgError ("Cannot allocate memory for uncompressed data");
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot allocate memory for uncompressed data.\nFailed also to delete package file");
else
PkgError ("Cannot allocate memory for uncompressed data");
goto err;
}
@ -295,8 +299,10 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
// Write the start marker
if (!SaveBufferToFile (MAG_START_MARKER, outputFile, strlen (MAG_START_MARKER), TRUE))
{
if (remove (outputFile))
PkgError ("Cannot write the start marker\nFailed also to delete package file");
else
PkgError ("Cannot write the start marker");
remove (outputFile);
goto err;
}
@ -319,7 +325,8 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
free (tmpBuffer);
StringCbPrintfA (tmpstr, sizeof(tmpstr), "Cannot load file \n'%s'", szTmpFilePath);
remove (outputFile);
if (remove (outputFile))
StringCbCatA (tmpstr, sizeof(tmpstr), "\nFailed also to delete package file");
PkgError (tmpstr);
goto err;
}
@ -352,7 +359,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
mputLong (szTmp32bitPtr, (unsigned __int32) uncompressedDataLen);
if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot write the total size of the uncompressed data.\nFailed also to delete package file");
else
PkgError ("Cannot write the total size of the uncompressed data");
goto err;
}
@ -362,7 +371,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
compressedBuffer = malloc (uncompressedDataLen + 524288); // + 512K reserve
if (compressedBuffer == NULL)
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot allocate memory for compressed data.\nFailed also to delete package file");
else
PkgError ("Cannot allocate memory for compressed data");
goto err;
}
@ -370,7 +381,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
compressedDataLen = CompressBuffer (compressedBuffer, buffer, uncompressedDataLen);
if (compressedDataLen <= 0)
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Failed to compress the data.\nFailed also to delete package file");
else
PkgError ("Failed to compress the data");
goto err;
}
@ -383,7 +396,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
mputLong (szTmp32bitPtr, (unsigned __int32) compressedDataLen);
if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot write the total size of the compressed data.\nFailed also to delete package file");
else
PkgError ("Cannot write the total size of the compressed data");
goto err;
}
@ -391,7 +406,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
// Write the compressed data
if (!SaveBufferToFile (compressedBuffer, outputFile, compressedDataLen, TRUE))
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot write compressed data to the package.\nFailed also to delete package file");
else
PkgError ("Cannot write compressed data to the package");
goto err;
}
@ -399,7 +416,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
// Write the end marker
if (!SaveBufferToFile (MagEndMarker, outputFile, strlen (MagEndMarker), TRUE))
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot write the end marker.\nFailed also to delete package file");
else
PkgError ("Cannot write the end marker");
goto err;
}
@ -417,7 +436,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
if (tmpBuffer == NULL)
{
handleWin32Error (hwndDlg);
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot load the package to compute CRC.\nFailed also to delete package file");
else
PkgError ("Cannot load the package to compute CRC");
goto err;
}
@ -431,7 +452,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir)
if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
{
remove (outputFile);
if (remove (outputFile))
PkgError ("Cannot write the total size of the compressed data.\nFailed also to delete package file");
else
PkgError ("Cannot write the total size of the compressed data");
goto err;
}