[SERVICES] Use pointers to const string (PCWSTR) instead of non-const for argv (#7440)

const PCWSTR* == const (const WCHAR*)* == (const WCHAR*) const *
This commit is contained in:
Hermès Bélusca-Maïto 2024-10-10 13:17:55 +02:00
parent 3fd6e34ab8
commit 90831e7451
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 25 additions and 24 deletions

View file

@ -1421,7 +1421,7 @@ ScmControlServiceEx(
_In_ SERVICE_STATUS_HANDLE hServiceStatus,
_In_opt_ DWORD dwServiceTag,
_In_opt_ DWORD argc,
_In_reads_opt_(argc) PWSTR* argv)
_In_reads_opt_(argc) const PCWSTR* argv)
{
DWORD dwError = ERROR_SUCCESS;
BOOL bResult;
@ -1760,7 +1760,7 @@ ScmWaitForServiceConnect(PSERVICE Service)
static DWORD
ScmStartUserModeService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
PROCESS_INFORMATION ProcessInformation;
STARTUPINFOW StartupInfo;
@ -1910,7 +1910,7 @@ Quit:
static DWORD
ScmLoadService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
PSERVICE_GROUP Group = Service->lpGroup;
DWORD dwError = ERROR_SUCCESS;
@ -2023,7 +2023,7 @@ ScmLoadService(PSERVICE Service,
DWORD
ScmStartService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
DWORD dwError = ERROR_SUCCESS;
SC_RPC_LOCK Lock = NULL;
@ -2042,7 +2042,8 @@ ScmStartService(PSERVICE Service,
if (!ScmInitialize)
{
dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
if (dwError != ERROR_SUCCESS) goto done;
if (dwError != ERROR_SUCCESS)
goto done;
}
/* Really start the service */

View file

@ -3320,7 +3320,7 @@ RStartServiceW(
return ERROR_SERVICE_MARKED_FOR_DELETE;
/* Start the service */
dwError = ScmStartService(lpService, argc, (LPWSTR*)argv);
dwError = ScmStartService(lpService, argc, (PCWSTR*)argv);
return dwError;
}
@ -4378,7 +4378,7 @@ RStartServiceA(
DWORD dwError = ERROR_SUCCESS;
PSERVICE_HANDLE hSvc;
PSERVICE lpService = NULL;
LPWSTR *lpVector = NULL;
PWSTR* pVector = NULL;
DWORD i;
DWORD dwLength;
@ -4417,25 +4417,25 @@ RStartServiceA(
/* Build a Unicode argument vector */
if (argc > 0)
{
lpVector = HeapAlloc(GetProcessHeap(),
pVector = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
argc * sizeof(LPWSTR));
if (lpVector == NULL)
argc * sizeof(PWSTR));
if (!pVector)
return ERROR_NOT_ENOUGH_MEMORY;
for (i = 0; i < argc; i++)
{
dwLength = MultiByteToWideChar(CP_ACP,
0,
((LPSTR*)argv)[i],
argv[i].StringPtr,
-1,
NULL,
0);
lpVector[i] = HeapAlloc(GetProcessHeap(),
pVector[i] = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwLength * sizeof(WCHAR));
if (lpVector[i] == NULL)
if (!pVector[i])
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
@ -4443,26 +4443,26 @@ RStartServiceA(
MultiByteToWideChar(CP_ACP,
0,
((LPSTR*)argv)[i],
argv[i].StringPtr,
-1,
lpVector[i],
pVector[i],
dwLength);
}
}
/* Start the service */
dwError = ScmStartService(lpService, argc, lpVector);
dwError = ScmStartService(lpService, argc, (PCWSTR*)pVector);
done:
/* Free the Unicode argument vector */
if (lpVector != NULL)
if (pVector)
{
for (i = 0; i < argc; i++)
{
if (lpVector[i] != NULL)
HeapFree(GetProcessHeap(), 0, lpVector[i]);
if (pVector[i])
HeapFree(GetProcessHeap(), 0, pVector[i]);
}
HeapFree(GetProcessHeap(), 0, lpVector);
HeapFree(GetProcessHeap(), 0, pVector);
}
return dwError;

View file

@ -186,7 +186,7 @@ VOID ScmAutoStartServices(VOID);
VOID ScmAutoShutdownServices(VOID);
DWORD ScmStartService(PSERVICE Service,
DWORD argc,
LPWSTR *argv);
const PCWSTR* argv);
DWORD ScmReferenceService(PSERVICE lpService);
DWORD ScmDereferenceService(PSERVICE lpService);