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

View file

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

View file

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