diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-07 02:07:38 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-07 02:39:43 +0100 |
commit | ae7ec4802a81770ff164e465b8d1fb51624ca093 (patch) | |
tree | 369c0ddf810ea03ae2d1426a661b54ca5288c34c /src/Common | |
parent | 229bd668f414cac163d12be9a3284b79d95b4ac0 (diff) | |
download | VeraCrypt-ae7ec4802a81770ff164e465b8d1fb51624ca093.tar.gz VeraCrypt-ae7ec4802a81770ff164e465b8d1fb51624ca093.zip |
Windows:Fix various issues and warnings reported by static code analysis tool Coverity.
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/BootEncryption.cpp | 46 | ||||
-rw-r--r-- | src/Common/Cmdline.c | 2 | ||||
-rw-r--r-- | src/Common/Combo.c | 2 | ||||
-rw-r--r-- | src/Common/Dlgcode.c | 14 | ||||
-rw-r--r-- | src/Common/Exception.h | 4 | ||||
-rw-r--r-- | src/Common/Format.c | 12 | ||||
-rw-r--r-- | src/Common/Keyfiles.c | 32 | ||||
-rw-r--r-- | src/Common/Keyfiles.h | 2 | ||||
-rw-r--r-- | src/Common/Password.c | 4 | ||||
-rw-r--r-- | src/Common/Progress.c | 26 | ||||
-rw-r--r-- | src/Common/Random.c | 6 | ||||
-rw-r--r-- | src/Common/Volumes.c | 8 |
12 files changed, 86 insertions, 72 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index b04507de..07eb9a99 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -691,7 +691,7 @@ namespace VeraCrypt GetSystemDriveConfiguration();
ProbeRealDriveSizeRequest request;
- StringCbCopyW (request.DeviceName, sizeof (request.DeviceName), DriveConfig.DrivePartition.DevicePath.c_str());
+ StringCchCopyW (request.DeviceName, ARRAYSIZE (request.DeviceName), DriveConfig.DrivePartition.DevicePath.c_str());
CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request));
DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize;
@@ -720,7 +720,7 @@ namespace VeraCrypt partPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition" << partNumber;
DISK_PARTITION_INFO_STRUCT diskPartInfo = {0};
- StringCbCopyW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), partPath.str().c_str());
+ StringCchCopyW (diskPartInfo.deviceName, ARRAYSIZE (diskPartInfo.deviceName), partPath.str().c_str());
try
{
@@ -833,7 +833,7 @@ namespace VeraCrypt memset (&openTestStruct, 0, sizeof (openTestStruct));
DWORD dwResult;
- StringCbCopyW (&openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath);
+ StringCchCopyW (&openTestStruct.wszFileName[0], ARRAYSIZE(openTestStruct.wszFileName),devicePath);
openTestStruct.bDetectTCBootLoader = TRUE;
@@ -935,7 +935,7 @@ namespace VeraCrypt bool BootEncryption::SystemDriveIsDynamic ()
{
GetSystemDriveConfigurationRequest request;
- StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCchCopyW (request.DevicePath, ARRAYSIZE (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
return request.DriveIsDynamic ? true : false;
@@ -1240,7 +1240,7 @@ namespace VeraCrypt throw ParameterIncorrect (SRC_POS);
GetSystemDriveConfigurationRequest request;
- StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCchCopyW (request.DevicePath, ARRAYSIZE (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
try
{
@@ -1973,7 +1973,7 @@ namespace VeraCrypt DWORD size = (DWORD) (sizeof (regKeyBuf) - strSize);
// SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly
- StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str());
+ StringCchCopyA ((char *) regKeyBuf, ARRAYSIZE(regKeyBuf), filter.c_str());
if (RegQueryValueExA (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
size = 1;
@@ -2115,6 +2115,7 @@ namespace VeraCrypt SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS);
if (service)
{
+ finally_do_arg (SC_HANDLE, service, { CloseServiceHandle (finally_arg); });
// ensure that its parameters are correct
throw_sys_if (!ChangeServiceConfig (service,
SERVICE_WIN32_OWN_PROCESS,
@@ -2585,23 +2586,26 @@ namespace VeraCrypt if (!systemPartitionOnly)
{
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber);
- Buffer sector (geometry.BytesPerSector);
+ if ((geometry.BytesPerSector > 0) && (geometry.BytesPerSector < TC_MAX_VOLUME_SECTOR_SIZE))
+ {
+ Buffer sector (geometry.BytesPerSector);
- Device device (config.DevicePath);
- device.CheckOpened (SRC_POS);
+ Device device (config.DevicePath);
+ device.CheckOpened (SRC_POS);
- try
- {
- device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.BytesPerSector);
- device.Read (sector.Ptr(), (DWORD) sector.Size());
- }
- catch (SystemException &e)
- {
- if (e.ErrorCode != ERROR_CRC)
+ try
{
- e.Show (ParentWindow);
- Error ("WHOLE_DRIVE_ENCRYPTION_PREVENTED_BY_DRIVERS", ParentWindow);
- throw UserAbort (SRC_POS);
+ device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.BytesPerSector);
+ device.Read (sector.Ptr(), (DWORD) sector.Size());
+ }
+ catch (SystemException &e)
+ {
+ if (e.ErrorCode != ERROR_CRC)
+ {
+ e.Show (ParentWindow);
+ Error ("WHOLE_DRIVE_ENCRYPTION_PREVENTED_BY_DRIVERS", ParentWindow);
+ throw UserAbort (SRC_POS);
+ }
}
}
}
@@ -2641,7 +2645,7 @@ namespace VeraCrypt void BootEncryption::RestrictPagingFilesToSystemPartition ()
{
wchar_t pagingFiles[128] = {0};
- StringCbCopyW (pagingFiles, sizeof(pagingFiles), L"X:\\pagefile.sys 0 0");
+ StringCchCopyW (pagingFiles, ARRAYSIZE(pagingFiles), L"X:\\pagefile.sys 0 0");
pagingFiles[0] = GetWindowsDirectory()[0];
throw_sys_if (!WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", pagingFiles, (DWORD) (wcslen (pagingFiles) + 2) * sizeof (wchar_t)));
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c index b140309f..759c63f5 100644 --- a/src/Common/Cmdline.c +++ b/src/Common/Cmdline.c @@ -173,7 +173,7 @@ int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx, {
/* Handles the case of space between parameter code
and value */
- StringCbCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
+ StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++;
return HAS_ARGUMENT;
diff --git a/src/Common/Combo.c b/src/Common/Combo.c index 56e0afc5..0340b23a 100644 --- a/src/Common/Combo.c +++ b/src/Common/Combo.c @@ -232,7 +232,7 @@ void DumpCombo (HWND hComboBox, int bClear) if (szTmp[0] != 0)
{
wchar_t q[MAX_PATH * 2] = { 0 };
- XmlQuoteTextW (szTmp, q, sizeof (q));
+ XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
}
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index e2b00f7a..4ffae65c 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -716,7 +716,7 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos) pszDesc = (wchar_t*) lpMsgBuf;
else
{
- StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"Error 0x%.8X", dwError);
+ StringCchPrintfW (szErrorValue, ARRAYSIZE (szErrorValue), L"Error 0x%.8X", dwError);
pszDesc = szErrorValue;
}
@@ -853,7 +853,7 @@ std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::w SelectObject (hdc, (HGDIOBJ) hFont);
wchar_t pathBuf[TC_MAX_PATH];
- StringCbCopyW (pathBuf, sizeof (pathBuf), path.c_str());
+ StringCchCopyW (pathBuf, ARRAYSIZE (pathBuf), path.c_str());
if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf;
@@ -4898,6 +4898,8 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg) if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0)
{
+ if (ci)
+ crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND);
return FALSE;
}
@@ -4905,6 +4907,8 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg) lpTestBuffer = (BYTE *) malloc(benchmarkBufferSize - (benchmarkBufferSize % 16));
if (lpTestBuffer == NULL)
{
+ if (ci)
+ crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND);
return FALSE;
}
@@ -8132,7 +8136,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile, {
dst = CreateFile (destinationFile,
GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
dwLastError = GetLastError();
if (dst == INVALID_HANDLE_VALUE)
{
@@ -9372,7 +9376,7 @@ void RestoreDefaultKeyFilesParam (void) KeyFileRemoveAll (&FirstKeyFile);
if (defaultKeyFilesParam.FirstKeyFile != NULL)
{
- FirstKeyFile = KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile);
+ KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile, &FirstKeyFile);
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles;
}
else
@@ -11295,7 +11299,7 @@ BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp) const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
BOOL installed = FALSE;
HKEY unistallKey;
- LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY, &unistallKey);
+ LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &unistallKey);
if (res != ERROR_SUCCESS)
{
SetLastError (res);
diff --git a/src/Common/Exception.h b/src/Common/Exception.h index a54f803d..f3635a1d 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -77,7 +77,7 @@ namespace VeraCrypt void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
@@ -93,7 +93,7 @@ namespace VeraCrypt void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
diff --git a/src/Common/Format.c b/src/Common/Format.c index a3200bb4..fe12c041 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -138,7 +138,7 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams) if (volParams->bDevice)
{
- StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath);
+ StringCchCopyW (deviceName, ARRAYSIZE(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName);
}
@@ -874,10 +874,10 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType) switch (fsType)
{
case FILESYS_NTFS:
- StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"NTFS");
+ StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"NTFS");
break;
case FILESYS_EXFAT:
- StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"EXFAT");
+ StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"EXFAT");
break;
default:
return FALSE;
@@ -886,10 +886,10 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType) if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatW(dllPath, sizeof(dllPath), L"\\fmifs.dll");
+ StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\fmifs.dll");
}
else
- StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
+ StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
hModule = LoadLibrary (dllPath);
@@ -902,7 +902,7 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType) return FALSE;
}
- StringCbCatW (dir, sizeof(dir), L":\\");
+ StringCchCatW (dir, ARRAYSIZE(dir), L":\\");
FormatExError = TRUE;
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c index 9dcf1dcc..9db05266 100644 --- a/src/Common/Keyfiles.c +++ b/src/Common/Keyfiles.c @@ -119,20 +119,26 @@ KeyFile *KeyFileClone (KeyFile *keyFile) }
-KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile)
+void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile)
{
- KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile);
- KeyFile *kf;
-
- if (firstKeyFile == NULL) return NULL;
- kf = firstKeyFile->Next;
- while (kf != NULL)
+ if (outputKeyFile)
{
- KeyFileAdd (cloneFirstKeyFile, KeyFileClone (kf));
- kf = kf->Next;
- }
+ KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile);
+ KeyFile *kf;
- return cloneFirstKeyFile;
+ KeyFileRemoveAll (outputKeyFile);
+ if (firstKeyFile)
+ {
+ kf = firstKeyFile->Next;
+ while (kf != NULL)
+ {
+ KeyFileAdd (cloneFirstKeyFile, KeyFileClone (kf));
+ kf = kf->Next;
+ }
+
+ *outputKeyFile = cloneFirstKeyFile;
+ }
+ }
}
@@ -451,7 +457,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa param = (KeyFilesDlgParam *) lParam;
origParam = *(KeyFilesDlgParam *) lParam;
- param->FirstKeyFile = KeyFileCloneAll (param->FirstKeyFile);
+ KeyFileCloneAll (param->FirstKeyFile, ¶m->FirstKeyFile);
LocalizeDialog (hwndDlg, "IDD_KEYFILES");
DragAcceptFiles (hwndDlg, TRUE);
@@ -637,7 +643,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
+ DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile);
}
diff --git a/src/Common/Keyfiles.h b/src/Common/Keyfiles.h index 2972a765..10b9b77e 100644 --- a/src/Common/Keyfiles.h +++ b/src/Common/Keyfiles.h @@ -38,7 +38,7 @@ typedef struct KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
void KeyFileRemoveAll (KeyFile **firstKeyFile);
KeyFile *KeyFileClone (KeyFile *keyFile);
-KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile);
+void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/src/Common/Password.c b/src/Common/Password.c index 59c82e51..8a93065d 100644 --- a/src/Common/Password.c +++ b/src/Common/Password.c @@ -43,8 +43,8 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword, UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
- GetWindowText (hPassword, szTmp1, sizeof (szTmp1));
- GetWindowText (hVerify, szTmp2, sizeof (szTmp2));
+ GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
+ GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
diff --git a/src/Common/Progress.c b/src/Common/Progress.c index 1d610def..19bd2171 100644 --- a/src/Common/Progress.c +++ b/src/Common/Progress.c @@ -78,23 +78,23 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
if (perc > 99.999999999)
- StringCbCopyW (text,sizeof(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
+ StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
else
- StringCbPrintfW (text, sizeof text, GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
+ StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
- StringCbCatW (text, sizeof(speed), L" ");
+ StringCchCatW (text, ARRAYSIZE(text), L" ");
}
else
{
GetSizeString (bytesDone, text, sizeof(text));
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
else
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
}
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
@@ -102,7 +102,7 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) if (!bShowStatus)
{
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
- StringCbCatW (speed, sizeof(speed), L" ");
+ StringCchCatW (speed, ARRAYSIZE(speed), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
}
@@ -111,15 +111,15 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
- StringCbPrintfW (text, sizeof(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
else if (sec >= 60 * 60 * 24 * 2)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
else if (sec >= 120 * 60)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 60), hours);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
else if (sec >= 120)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / 60, minutes);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
else
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec, seconds);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
}
diff --git a/src/Common/Random.c b/src/Common/Random.c index 31dea511..21c18dad 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c @@ -671,10 +671,10 @@ BOOL SlowPoll (void) wchar_t dllPath[MAX_PATH];
if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatW(dllPath, sizeof(dllPath), L"\\NETAPI32.DLL");
+ StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\NETAPI32.DLL");
}
else
- StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
+ StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
hNetAPI32 = LoadLibrary (dllPath);
if (hNetAPI32 != NULL)
@@ -725,7 +725,7 @@ BOOL SlowPoll (void) wchar_t szDevice[24];
/* Check whether we can access this device */
- StringCbPrintfW (szDevice, sizeof(szDevice), L"\\\\.\\PhysicalDrive%d", nDrive);
+ StringCchPrintfW (szDevice, ARRAYSIZE(szDevice), L"\\\\.\\PhysicalDrive%d", nDrive);
hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
diff --git a/src/Common/Volumes.c b/src/Common/Volumes.c index 50fd8765..b7c77e9c 100644 --- a/src/Common/Volumes.c +++ b/src/Common/Volumes.c @@ -1022,16 +1022,16 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea, for (i = 0; i < j; i++)
{
wchar_t tmp2[8] = {0};
- StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
- StringCbCatW (MasterKeyGUIView, sizeof(MasterKeyGUIView), tmp2);
+ StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
+ StringCchCatW (MasterKeyGUIView, ARRAYSIZE(MasterKeyGUIView), tmp2);
}
HeaderKeyGUIView[0] = 0;
for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++)
{
wchar_t tmp2[8];
- StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
- StringCbCatW (HeaderKeyGUIView, sizeof(HeaderKeyGUIView), tmp2);
+ StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
+ StringCchCatW (HeaderKeyGUIView, ARRAYSIZE(HeaderKeyGUIView), tmp2);
}
if (dots3)
|