From: Alex Henrie alexhenrie24@gmail.com
--- dlls/httpapi/httpapi_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/dlls/httpapi/httpapi_main.c b/dlls/httpapi/httpapi_main.c index 10131fdd029..b808b627174 100644 --- a/dlls/httpapi/httpapi_main.c +++ b/dlls/httpapi/httpapi_main.c @@ -185,7 +185,7 @@ ULONG WINAPI HttpSetServiceConfiguration( HANDLE handle, HTTP_SERVICE_CONFIG_ID ULONG WINAPI HttpCreateHttpHandle(HANDLE *handle, ULONG reserved) { OBJECT_ATTRIBUTES attr = {sizeof(attr)}; - UNICODE_STRING string; + UNICODE_STRING string = RTL_CONSTANT_STRING(L"\Device\Http\ReqQueue"); IO_STATUS_BLOCK iosb;
TRACE("handle %p, reserved %#lx.\n", handle, reserved); @@ -193,7 +193,6 @@ ULONG WINAPI HttpCreateHttpHandle(HANDLE *handle, ULONG reserved) if (!handle) return ERROR_INVALID_PARAMETER;
- RtlInitUnicodeString(&string, L"\Device\Http\ReqQueue"); attr.ObjectName = &string; return RtlNtStatusToDosError(NtCreateFile(handle, 0, &attr, &iosb, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_NON_DIRECTORY_FILE, NULL, 0)); @@ -741,7 +740,7 @@ ULONG WINAPI HttpCreateRequestQueue(HTTPAPI_VERSION version, const WCHAR *name, SECURITY_ATTRIBUTES *sa, ULONG flags, HANDLE *handle) { OBJECT_ATTRIBUTES attr = {sizeof(attr)}; - UNICODE_STRING string; + UNICODE_STRING string = RTL_CONSTANT_STRING(L"\Device\Http\ReqQueue"); IO_STATUS_BLOCK iosb;
TRACE("version %u.%u, name %s, sa %p, flags %#lx, handle %p.\n", @@ -753,7 +752,6 @@ ULONG WINAPI HttpCreateRequestQueue(HTTPAPI_VERSION version, const WCHAR *name, if (flags) FIXME("Unhandled flags %#lx.\n", flags);
- RtlInitUnicodeString(&string, L"\Device\Http\ReqQueue"); attr.ObjectName = &string; if (sa && sa->bInheritHandle) attr.Attributes |= OBJ_INHERIT;
I don't understand, what's wrong with using RtlInitUnicodeString() on a static constant?
On Wed Feb 8 18:43:07 2023 +0000, Zebediah Figura wrote:
I don't understand, what's wrong with using RtlInitUnicodeString() on a static constant?
It's not a logic error, it just results in an unnecessary call to wcslen and makes it less clear that the string is not being duplicated into new memory. For example, the following does not result in any warnings when compiled with `-fanalyzer`:
``` UNICODE_STRING s; RtlInitUnicodeString(&s, L"Hello world!"); s.Buffer[0] = 0; ```
But the following does result in a warning when compiled with `-fanalyzer`:
``` UNICODE_STRING s = RTL_CONSTANT_STRING(L"Hello world!"); s.Buffer[0] = 0; ```
Okay, thanks for the explanation.
This merge request was approved by Zebediah Figura.