[KS]
[reactos.git] / reactos / drivers / ksfilter / ks / swenum.c
index 8430b64..119d13d 100644 (file)
@@ -6,8 +6,13 @@
  * PROGRAMMER:      Johannes Anderwald
  */
 
+#include "precomp.h"
 
-#include "priv.h"
+#include <stdio.h>
+#include <swenum.h>
+
+#define NDEBUG
+#include <debug.h>
 
 LONG KsDeviceCount = 0;
 
@@ -324,7 +329,7 @@ KspCreateDeviceReference(
     IN LPWSTR ReferenceString)
 {
     LPWSTR DeviceName;
-    ULONG Length;
+    SIZE_T Length;
     PLIST_ENTRY Entry;
     PBUS_DEVICE_ENTRY DeviceEntry = NULL; /* GCC warning */
     BOOLEAN ItemExists = FALSE;
@@ -518,7 +523,7 @@ KspBusQueryReferenceString(
     IN OUT PWCHAR *String)
 {
     LPWSTR Name;
-    ULONG Length;
+    SIZE_T Length;
     PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension = (PBUS_ENUM_DEVICE_EXTENSION)Context;
 
     /* sanity checks */
@@ -660,7 +665,7 @@ KspDoReparseForIrp(
     PIRP Irp,
     PBUS_DEVICE_ENTRY DeviceEntry)
 {
-    ULONG Length;
+    SIZE_T Length;
     LPWSTR Buffer;
     PIO_STACK_LOCATION IoStack;
 
@@ -678,7 +683,7 @@ KspDoReparseForIrp(
     Length += wcslen(DeviceEntry->Instance);
 
     /* zero byte and '\\' */
-    Length += 2; 
+    Length += 2;
 
     /* allocate buffer */
     Buffer = AllocateItem(NonPagedPool, Length * sizeof(WCHAR));
@@ -752,12 +757,13 @@ KspStartBusDevice(
     NTSTATUS Status;
     ULONG ResultLength;
     LPWSTR Name;
+    ULONG NameLength;
     PBUS_DEVICE_ENTRY DeviceEntry;
 
     /* FIXME handle pending remove */
 
     /* get full device name */
-    Status = IoGetDeviceProperty(DeviceObject, DevicePropertyPhysicalDeviceObjectName, sizeof(PDOName), (PVOID)PDOName, &ResultLength);
+    Status = IoGetDeviceProperty(DeviceObject, DevicePropertyPhysicalDeviceObjectName, sizeof(PDOName), PDOName, &ResultLength);
 
     if (!NT_SUCCESS(Status))
     {
@@ -766,7 +772,8 @@ KspStartBusDevice(
     }
 
     /* allocate device name buffer */
-    Name = AllocateItem(NonPagedPool, (ResultLength + 1) * sizeof(WCHAR));
+    NameLength = ResultLength + sizeof(UNICODE_NULL);
+    Name = AllocateItem(NonPagedPool, NameLength);
     if (!Name)
     {
         /* no memory */
@@ -774,7 +781,7 @@ KspStartBusDevice(
     }
 
     /* copy name */
-    wcscpy(Name, PDOName);
+    NT_VERIFY(NT_SUCCESS(RtlStringCbCopyW(Name, NameLength, PDOName)));
 
     /* TODO: time stamp creation time */
 
@@ -880,7 +887,7 @@ KspQueryId(
     PBUS_DEVICE_ENTRY DeviceEntry;
     PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension;
     LPWSTR Name;
-    ULONG Length;
+    SIZE_T Length;
 
     /* get current irp stack location */
     IoStack = IoGetCurrentIrpStackLocation(Irp);
@@ -967,7 +974,7 @@ KspInstallInterface(
     IN PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension,
     IN PSWENUM_INSTALL_INTERFACE InstallInterface)
 {
-    ULONG Length, Index;
+    SIZE_T Length, Index;
     UNICODE_STRING DeviceString, InterfaceString, ReferenceString;
     HANDLE hKey, hDeviceKey, hInterfaceKey, hReferenceKey;
     NTSTATUS Status;
@@ -1364,7 +1371,7 @@ KsGetBusEnumIdentifier(
     PDEV_EXTENSION DeviceExtension;
     PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension;
     PIO_STACK_LOCATION IoStack;
-    ULONG Length;
+    SIZE_T Length;
     NTSTATUS Status;
     LPWSTR Buffer;
 
@@ -1484,7 +1491,7 @@ KsCreateBusEnumObject(
     IN REFGUID InterfaceGuid OPTIONAL,
     IN PWCHAR ServiceRelativePath OPTIONAL)
 {
-    ULONG Length;
+    SIZE_T Length;
     NTSTATUS Status = STATUS_SUCCESS;
     UNICODE_STRING ServiceKeyPath = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\");
     PBUS_ENUM_DEVICE_EXTENSION BusDeviceExtension;
@@ -1532,7 +1539,7 @@ KsCreateBusEnumObject(
     }
 
     BusDeviceExtension->ServicePath.Length = 0;
-    BusDeviceExtension->ServicePath.MaximumLength = Length;
+    BusDeviceExtension->ServicePath.MaximumLength = (USHORT)Length;
     BusDeviceExtension->ServicePath.Buffer = AllocateItem(NonPagedPool, Length);
 
     if (!BusDeviceExtension->ServicePath.Buffer)
@@ -2120,7 +2127,7 @@ KsServiceBusEnumPnpRequest(
 /*
     @implemented
 */
-KSDDKAPI 
+KSDDKAPI
 NTSTATUS
 NTAPI
 KsRemoveBusEnumInterface(