mirror of
https://github.com/reactos/reactos.git
synced 2024-10-01 06:57:08 +00:00
[MMSYS]: Improve AddSoundProfile, by Victor Martinez Calvo (with 1 minor modification by myself):
◾ Don't return TRUE when CB_SETITEMDATA fails. ◾ Avoid pScheme NULL dereference if allocation fails. CID 1223154 ◾ Avoid overflowing the destiny buffer by using StringCchCopy() CID 510953 and: 1) Make it more readable by returning as soon as possible when an error happens. 2) Make it more readable by reducing the nested ifs-checks. 3) Remove the added string in the combobox if the sound scheme buffer mem allocation fails (pt.3 modified). CORE-11603 #resolve #comment Thanks! svn path=/trunk/; revision=72000
This commit is contained in:
parent
42abc25acc
commit
b79e7d2eee
|
@ -5,11 +5,14 @@
|
||||||
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
|
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
|
||||||
* Johannes Anderwald <janderwald@reactos.com>
|
* Johannes Anderwald <janderwald@reactos.com>
|
||||||
* Dmitry Chapyshev <dmitry@reactos.org>
|
* Dmitry Chapyshev <dmitry@reactos.org>
|
||||||
|
* Victor Martinez Calvo <victor.martinez@reactos.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mmsys.h"
|
#include "mmsys.h"
|
||||||
|
|
||||||
#include <commdlg.h>
|
#include <commdlg.h>
|
||||||
|
#include <strsafe.h>
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
struct __APP_MAP__;
|
struct __APP_MAP__;
|
||||||
|
@ -291,6 +294,8 @@ AddSoundProfile(HWND hwndDlg, HKEY hKey, TCHAR * szSubKey, BOOL SetDefault)
|
||||||
HKEY hSubKey;
|
HKEY hSubKey;
|
||||||
TCHAR szValue[MAX_PATH];
|
TCHAR szValue[MAX_PATH];
|
||||||
DWORD dwValue, dwResult;
|
DWORD dwValue, dwResult;
|
||||||
|
LRESULT lResult;
|
||||||
|
PSOUND_SCHEME_CONTEXT pScheme;
|
||||||
|
|
||||||
if (RegOpenKeyEx(hKey,
|
if (RegOpenKeyEx(hKey,
|
||||||
szSubKey,
|
szSubKey,
|
||||||
|
@ -309,28 +314,36 @@ AddSoundProfile(HWND hwndDlg, HKEY hKey, TCHAR * szSubKey, BOOL SetDefault)
|
||||||
(LPBYTE)szValue,
|
(LPBYTE)szValue,
|
||||||
&dwValue);
|
&dwValue);
|
||||||
RegCloseKey(hSubKey);
|
RegCloseKey(hSubKey);
|
||||||
if (dwResult == ERROR_SUCCESS)
|
|
||||||
|
if (dwResult != ERROR_SUCCESS)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Try to add the new profile */
|
||||||
|
lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue);
|
||||||
|
if (lResult == CB_ERR)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Allocate the profile scheme buffer */
|
||||||
|
pScheme = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SOUND_SCHEME_CONTEXT));
|
||||||
|
if (pScheme == NULL)
|
||||||
{
|
{
|
||||||
LRESULT lResult = SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue);
|
/* We failed to allocate the buffer, no need to keep a dangling string in the combobox */
|
||||||
if (lResult != CB_ERR)
|
SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_DELETESTRING, (WPARAM)lResult, (LPARAM)0);
|
||||||
{
|
return FALSE;
|
||||||
PSOUND_SCHEME_CONTEXT pScheme = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SOUND_SCHEME_CONTEXT));
|
|
||||||
if (pScheme != NULL)
|
|
||||||
{
|
|
||||||
_tcscpy(pScheme->szDesc, szValue);
|
|
||||||
_tcscpy(pScheme->szName, szSubKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringCchCopy(pScheme->szDesc, MAX_PATH, szValue);
|
||||||
|
StringCchCopy(pScheme->szName, MAX_PATH, szSubKey);
|
||||||
|
|
||||||
|
/* Associate the value with the item in the combobox */
|
||||||
SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pScheme);
|
SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pScheme);
|
||||||
|
|
||||||
|
/* Optionally, select the profile */
|
||||||
if (SetDefault)
|
if (SetDefault)
|
||||||
{
|
|
||||||
SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0);
|
SendDlgItemMessage(hwndDlg, IDC_SOUND_SCHEME, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0);
|
||||||
}
|
|
||||||
}
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DWORD
|
DWORD
|
||||||
|
|
Loading…
Reference in a new issue