Index: trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp
===================================================================
--- trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp	(revision 62710)
+++ trunk/src/VBox/HostDrivers/VBoxNetFlt/win/drv/VBoxNetFltRt-win.cpp	(revision 62711)
@@ -1,7 +1,7 @@
 /* $Id$ */
 /** @file
- * VBoxNetFltRt-win.cpp - Bridged Networking Driver, Windows Specific Code.
- * NetFlt Runtime
- */
+ * VBoxNetFltRt-win.cpp - Bridged Networking Driver, Windows Specific Runtime Code.
+ */
+
 /*
  * Copyright (C) 2011-2016 Oracle Corporation
@@ -15,13 +15,19 @@
  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  */
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
 #include "VBoxNetFltCmn-win.h"
 #include <VBox/intnetinline.h>
 #include <iprt/thread.h>
 
-RT_C_DECLS_BEGIN
-#include <tdikrnl.h>
-RT_C_DECLS_END
+#include <iprt/nt/tdikrnl.h>
 #include <mstcpip.h>
 
+
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
 /** represents the job element of the job queue
  * see comments for VBOXNETFLT_JOB_QUEUE */
@@ -71,5 +77,5 @@
 #endif
     NDIS_STATUS Status;
-}CREATE_INSTANCE_CONTEXT, *PCREATE_INSTANCE_CONTEXT;
+} CREATE_INSTANCE_CONTEXT, *PCREATE_INSTANCE_CONTEXT;
 
 /*contexts used for our jobs */
@@ -81,5 +87,5 @@
     bool fRediscovery;
     int Status;
-}ATTACH_INFO, *PATTACH_INFO;
+} ATTACH_INFO, *PATTACH_INFO;
 
 /* general worker context */
@@ -88,5 +94,5 @@
     PVBOXNETFLTINS pNetFltIf;
     int Status;
-}WORKER_INFO, *PWORKER_INFO;
+} WORKER_INFO, *PWORKER_INFO;
 
 /* idc initialization */
@@ -98,8 +104,10 @@
     volatile int rc;
     KEVENT hCompletionEvent;
-}INIT_IDC_INFO, *PINIT_IDC_INFO;
-
-
-/** globals */
+} INIT_IDC_INFO, *PINIT_IDC_INFO;
+
+
+/*********************************************************************************************************************************
+*   Global Variables                                                                                                             *
+*********************************************************************************************************************************/
 /** global job queue. some operations are required to be done at passive level, e.g. thread creation, adapter bind/unbind initiation,
  * while IntNet typically calls us APC_LEVEL, so we just create a system thread in our DriverEntry and enqueue the jobs to that thread */
@@ -107,4 +115,5 @@
 volatile static bool g_bVBoxIdcInitialized;
 INIT_IDC_INFO g_VBoxInitIdcInfo;
+
 /**
  * The (common) global data.
@@ -114,7 +123,15 @@
 VBOXNETFLTGLOBALS_WIN g_VBoxNetFltGlobalsWin = {0};
 
+
+/*********************************************************************************************************************************
+*   Defined Constants And Macros                                                                                                 *
+*********************************************************************************************************************************/
 #define LIST_ENTRY_2_JOB(pListEntry) \
     ( (PVBOXNETFLT_JOB)((uint8_t *)(pListEntry) - RT_OFFSETOF(VBOXNETFLT_JOB, ListEntry)) )
 
+
+/*********************************************************************************************************************************
+*   Internal Functions                                                                                                           *
+*********************************************************************************************************************************/
 static int vboxNetFltWinAttachToInterface(PVBOXNETFLTINS pThis, void * pContext, bool fRediscovery);
 static int vboxNetFltWinConnectIt(PVBOXNETFLTINS pThis);
@@ -126,4 +143,6 @@
 static int vboxNetFltWinStopInitIdcProbing();
 
+
+
 /** makes the current thread to sleep for the given number of miliseconds */
 DECLHIDDEN(void) vboxNetFltWinSleep(ULONG milis)
@@ -160,20 +179,18 @@
  */
 /* allocates and zeroes the nonpaged memory of a given size */
-DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMemAlloc(PVOID* ppMemBuf, UINT cbLength)
+DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMemAlloc(PVOID *ppvMemBuf, UINT cbLength)
 {
 #ifdef DEBUG_NETFLT_USE_EXALLOC
-    *ppMemBuf = ExAllocatePoolWithTag(NonPagedPool, cbLength, VBOXNETFLT_MEM_TAG);
-    if (*ppMemBuf)
-    {
-        NdisZeroMemory(*ppMemBuf, cbLength);
+    *ppvMemBuf = ExAllocatePoolWithTag(NonPagedPool, cbLength, VBOXNETFLT_MEM_TAG);
+    if (*ppvMemBuf)
+    {
+        NdisZeroMemory(*ppvMemBuf, cbLength);
         return NDIS_STATUS_SUCCESS;
     }
     return NDIS_STATUS_FAILURE;
 #else
-    NDIS_STATUS fStatus = NdisAllocateMemoryWithTag(ppMemBuf, cbLength, VBOXNETFLT_MEM_TAG);
+    NDIS_STATUS fStatus = NdisAllocateMemoryWithTag(ppvMemBuf, cbLength, VBOXNETFLT_MEM_TAG);
     if (fStatus == NDIS_STATUS_SUCCESS)
-    {
-        NdisZeroMemory(*ppMemBuf, cbLength);
-    }
+        NdisZeroMemory(*ppvMemBuf, cbLength);
     return fStatus;
 #endif
@@ -273,5 +290,4 @@
 static NDIS_STATUS vboxNetFltWinNdisBufferMoveToSG0(PNDIS_BUFFER pBuffer, PINTNETSG pSG)
 {
-    UINT cSegs = 0;
     PINTNETSEG paSeg;
     uint8_t * ptr;
@@ -547,5 +563,4 @@
         PNDIS_BUFFER pCurrentBuffer = NULL;
         UINT cBufferCount;
-        UINT uBytesCopied = 0;
         UINT cbPacketLength;
 
@@ -1399,5 +1414,6 @@
     return NDIS_STATUS_NOT_SUPPORTED;
 }
-#else /* if defined VBOXNETADP */
+
+#else /* VBOXNETADP */
 
 /**
@@ -1442,22 +1458,14 @@
 }
 
-static int vboxNetFltWinWchar2Int(WCHAR c, uint8_t * pv)
+static int vboxNetFltWinWchar2Byte(WCHAR c, uint8_t *pb)
 {
     if (c >= L'A' && c <= L'F')
-    {
-        *pv = (c - L'A') + 10;
-    }
+        *pb = (c - L'A') + 10;
     else if (c >= L'a' && c <= L'f')
-    {
-        *pv = (c - L'a') + 10;
-    }
+        *pb = (c - L'a') + 10;
     else if (c >= L'0' && c <= L'9')
-    {
-        *pv = (c - L'0');
-    }
+        *pb = (c - L'0');
     else
-    {
         return VERR_INVALID_PARAMETER;
-    }
     return VINF_SUCCESS;
 }
@@ -1465,6 +1473,4 @@
 DECLHIDDEN(int) vboxNetFltWinMACFromNdisString(RTMAC *pMac, PNDIS_STRING pNdisString)
 {
-    int i, rc;
-    PWSTR pString;
 
     /* validate parameters */
@@ -1473,20 +1479,16 @@
     AssertReturn(pNdisString->Length >= 12*sizeof(pNdisString->Buffer[0]), VERR_INVALID_PARAMETER);
 
-    pString = pNdisString->Buffer;
-
-    for (i = 0; i < 6; i++)
+    int rc = VINF_SUCCESS;
+    PWSTR pString = pNdisString->Buffer;
+    for (int i = 0; i < 6; i++)
     {
         uint8_t v1, v2;
-        rc = vboxNetFltWinWchar2Int(pString[0], &v1);
+        rc = vboxNetFltWinWchar2Byte(pString[0], &v1);
         if (RT_FAILURE(rc))
-        {
             break;
-        }
-
-        rc = vboxNetFltWinWchar2Int(pString[1], &v2);
+
+        rc = vboxNetFltWinWchar2Byte(pString[1], &v2);
         if (RT_FAILURE(rc))
-        {
             break;
-        }
 
         pMac->au8[i] = (v1 << 4) | v2;
@@ -1498,5 +1500,6 @@
 }
 
-#endif
+#endif /* VBOXNETADP */
+
 /**
  * creates a NDIS_PACKET from the PINTNETSG
@@ -1762,8 +1765,10 @@
 //#endif
                 }
+#ifndef VBOXNETADP /* unreachable for VBOXNETADP because of the above return */
                 vboxNetFltWinMpDeregister(&g_VBoxNetFltGlobalsWin.Mp);
-#ifndef VBOXNETADP
+# ifndef VBOXNETADP
                 NdisFreeSpinLock(&g_VBoxNetFltGlobalsWin.lockFilters);
-#endif /* VBOXNETADP */
+# endif
+#endif
             }
             vboxNetFltWinJobFiniQueue(&g_VBoxJobQueue);
@@ -1961,5 +1966,4 @@
     int rc;
 #endif
-    BOOLEAN bCallFiniOnFail = FALSE;
 
     LogFlowFunc(("ENTER: pWinIf 0x%p\n", pWinIf));
@@ -2024,18 +2028,16 @@
                             return NDIS_STATUS_SUCCESS;
 #ifndef VBOXNETADP
-                            vboxNetFltWinMemFree(pWinIf->MpDeviceName.Buffer);
+                            // unreachable: vboxNetFltWinMemFree(pWinIf->MpDeviceName.Buffer);
                         }
                         RTSemFastMutexDestroy(pWinIf->hSynchRequestMutex);
                     }
                     else
-                    {
                         Status = NDIS_STATUS_FAILURE;
-                    }
                     NdisFreePacketPool(pWinIf->hSendPacketPool);
                 }
                 NdisFreeBufferPool(pWinIf->hSendBufferPool);
             }
-#endif
             NdisFreeBufferPool(pWinIf->hRecvBufferPool);
+#endif
         }
         NdisFreePacketPool(pWinIf->hRecvPacketPool);
@@ -2148,5 +2150,5 @@
     PNDIS_BUFFER pBuffer1;
     UINT uTotalPacketLength1;
-    uint8_t* pMemBuf1;
+    uint8_t *pbMemBuf1 = NULL;
     UINT cbLength1 = 0;
 
@@ -2154,5 +2156,5 @@
     PNDIS_BUFFER pBuffer2;
     UINT uTotalPacketLength2;
-    uint8_t* pMemBuf2;
+    uint8_t *pbMemBuf2 = NULL;
     UINT cbLength2 = 0;
     bool bMatch = true;
@@ -2193,24 +2195,24 @@
             if (!cbLength1)
             {
-                NdisQueryBufferSafe(pBuffer1, &pMemBuf1, &cbLength1, NormalPagePriority);
+                NdisQueryBufferSafe(pBuffer1, &pbMemBuf1, &cbLength1, NormalPagePriority);
                 NdisGetNextBuffer(pBuffer1, &pBuffer1);
             }
             else
             {
-                Assert(pMemBuf1);
+                Assert(pbMemBuf1);
                 Assert(ucbLength2Match);
-                pMemBuf1 += ucbLength2Match;
+                pbMemBuf1 += ucbLength2Match;
             }
 
             if (!cbLength2)
             {
-                NdisQueryBufferSafe(pBuffer2, &pMemBuf2, &cbLength2, NormalPagePriority);
+                NdisQueryBufferSafe(pBuffer2, &pbMemBuf2, &cbLength2, NormalPagePriority);
                 NdisGetNextBuffer(pBuffer2, &pBuffer2);
             }
             else
             {
-                Assert(pMemBuf2);
+                Assert(pbMemBuf2);
                 Assert(ucbLength2Match);
-                pMemBuf2 += ucbLength2Match;
+                pbMemBuf2 += ucbLength2Match;
             }
 
@@ -2218,5 +2220,5 @@
             ucbLength2Match = MIN(ucbLength2Match, cbLength2);
 
-            if (memcmp((PVOID*)pMemBuf1, (PVOID*)pMemBuf2, ucbLength2Match))
+            if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match))
             {
                 bMatch = false;
@@ -2253,8 +2255,8 @@
     PNDIS_BUFFER pBuffer1;
     UINT uTotalPacketLength1;
-    uint8_t* pMemBuf1;
+    uint8_t *pbMemBuf1 = NULL;
     UINT cbLength1 = 0;
     UINT uTotalPacketLength2 = pSG->cbTotal;
-    uint8_t* pMemBuf2;
+    uint8_t *pbMemBuf2 = NULL;
     UINT cbLength2 = 0;
     bool bMatch = true;
@@ -2293,12 +2295,12 @@
             if (!cbLength1)
             {
-                NdisQueryBufferSafe(pBuffer1, &pMemBuf1, &cbLength1, NormalPagePriority);
+                NdisQueryBufferSafe(pBuffer1, &pbMemBuf1, &cbLength1, NormalPagePriority);
                 NdisGetNextBuffer(pBuffer1, &pBuffer1);
             }
             else
             {
-                Assert(pMemBuf1);
+                Assert(pbMemBuf1);
                 Assert(ucbLength2Match);
-                pMemBuf1 += ucbLength2Match;
+                pbMemBuf1 += ucbLength2Match;
             }
 
@@ -2306,5 +2308,5 @@
             {
                 Assert(i < pSG->cSegsUsed);
-                pMemBuf2 = (uint8_t*)pSG->aSegs[i].pv;
+                pbMemBuf2 = (uint8_t*)pSG->aSegs[i].pv;
                 cbLength2 = pSG->aSegs[i].cb;
                 i++;
@@ -2312,7 +2314,7 @@
             else
             {
-                Assert(pMemBuf2);
+                Assert(pbMemBuf2);
                 Assert(ucbLength2Match);
-                pMemBuf2 += ucbLength2Match;
+                pbMemBuf2 += ucbLength2Match;
             }
 
@@ -2320,5 +2322,5 @@
             ucbLength2Match = MIN(ucbLength2Match, cbLength2);
 
-            if (memcmp((PVOID*)pMemBuf1, (PVOID*)pMemBuf2, ucbLength2Match))
+            if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match))
             {
                 bMatch = false;
@@ -2352,9 +2354,9 @@
 {
     UINT uTotalPacketLength1 = pSG1->cbTotal;
-    PVOID pMemBuf1;
+    PVOID pbMemBuf1 = NULL;
     UINT cbLength1 = 0;
     UINT i1 = 0;
     UINT uTotalPacketLength2 = pSG2->cbTotal;
-    PVOID pMemBuf2;
+    PVOID pbMemBuf2 = NULL;
     UINT cbLength2 = 0;
 
@@ -2393,5 +2395,5 @@
             {
                 Assert(i1 < pSG1->cSegsUsed);
-                pMemBuf1 = pSG1->aSegs[i1].pv;
+                pbMemBuf1 = pSG1->aSegs[i1].pv;
                 cbLength1 = pSG1->aSegs[i1].cb;
                 i1++;
@@ -2401,5 +2403,5 @@
             {
                 Assert(i2 < pSG2->cSegsUsed);
-                pMemBuf2 = pSG2->aSegs[i2].pv;
+                pbMemBuf2 = pSG2->aSegs[i2].pv;
                 cbLength2 = pSG2->aSegs[i2].cb;
                 i2++;
@@ -2409,5 +2411,5 @@
             ucbLength2Match = MIN(ucbLength2Match, cbLength2);
 
-            if (memcmp(pMemBuf1, pMemBuf2, ucbLength2Match))
+            if (memcmp(pbMemBuf1, pbMemBuf2, ucbLength2Match))
             {
                 bMatch = false;
@@ -2677,4 +2679,6 @@
 #ifndef VBOXNETFLT_NO_PACKET_QUEUE
     vboxNetFltWinQuFiniPacketQueue(pInstance);
+#else
+    RT_NOREF1(pInstance);
 #endif
     return NDIS_STATUS_SUCCESS;
@@ -2776,4 +2780,5 @@
     return false;
 #else
+    RT_NOREF1(pThis);
     return true;
 #endif
@@ -2837,5 +2842,6 @@
                 /* rediscovery means adaptor bind is performed while intnet is already using it
                  * i.e. adaptor was unbound while being used by intnet and now being bound back again */
-                Assert(((VBOXNETFTLINSSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState)) == kVBoxNetFltInsState_Connected);
+                Assert(   ((VBOXNETFTLINSSTATE)ASMAtomicUoReadU32((uint32_t volatile *)&pThis->enmState))
+                       == kVBoxNetFltInsState_Connected);
             }
 #ifndef VBOXNETADP
@@ -2856,7 +2862,5 @@
                 {
                     if (!pAttachInfo->fRediscovery)
-                    {
                         vboxNetFltWinDrvReference();
-                    }
 #ifndef VBOXNETADP
                     if (pThis->u.s.WinIf.OpenCloseStatus == NDIS_STATUS_SUCCESS)
@@ -2884,4 +2888,5 @@
                         return;
                     }
+#ifndef VBOXNETADP /* unreachable for VBOXNETADP because of the return above */
                     AssertBreakpoint();
 
@@ -2890,8 +2895,9 @@
                         vboxNetFltWinDrvDereference();
                     }
-#ifndef VBOXNETADP
+# ifndef VBOXNETADP
                     vboxNetFltWinPtDoUnbinding(pThis, true);
-#else
-                    vboxNetFltWinMpDoDeinitialization(pThis);
+/*# else - unreachable
+                    vboxNetFltWinMpDoDeinitialization(pThis); */
+# endif
 #endif
                 }
@@ -2945,4 +2951,5 @@
 static NTSTATUS vboxNetFltWinPtDevDispatch(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
 {
+    RT_NOREF1(pDevObj);
     PIO_STACK_LOCATION pIrpSl = IoGetCurrentIrpStackLocation(pIrp);;
     NTSTATUS Status = STATUS_SUCCESS;
@@ -3092,20 +3099,15 @@
 int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
 {
+    RT_NOREF1(pvIfData);
     int rc = VINF_SUCCESS;
     uint32_t cRefs = 0;
 #ifndef VBOXNETADP
     if (fDst & INTNETTRUNKDIR_WIRE)
-    {
         cRefs++;
-    }
     if (fDst & INTNETTRUNKDIR_HOST)
-    {
         cRefs++;
-    }
 #else
-    if (fDst & INTNETTRUNKDIR_WIRE || fDst & INTNETTRUNKDIR_HOST)
-    {
+    if ((fDst & INTNETTRUNKDIR_WIRE) || (fDst & INTNETTRUNKDIR_HOST))
         cRefs = 1;
-    }
 #endif
 
@@ -3144,12 +3146,9 @@
 #if defined(DEBUG_NETFLT_PACKETS) || !defined(VBOX_LOOPBACK_USEFLAGS)
                 /* the status is NOT pending, complete the packet */
-                bool bTmp = vboxNetFltWinLbRemoveSendPacket(pThis, pPacket);
-                Assert(bTmp);
+                bool fTmp = vboxNetFltWinLbRemoveSendPacket(pThis, pPacket);
+                Assert(fTmp); NOREF(fTmp);
 #endif
                 if (!NT_SUCCESS(fStatus))
-                {
-                    /* TODO: convert status to VERR_xxx */
-                    rc = VERR_GENERAL_FAILURE;
-                }
+                    rc = VERR_GENERAL_FAILURE; /** @todo convert status to VERR_xxx */
 
                 vboxNetFltWinFreeSGNdisPacket(pPacket, true);
@@ -3411,4 +3410,5 @@
                                     PTDI_PNP_CONTEXT Context)
 {
+    RT_NOREF2(DeviceName, Context);
     vboxNetFltWinNotifyHostAddress(Address, true);
 }
@@ -3418,4 +3418,5 @@
                                     PTDI_PNP_CONTEXT Context)
 {
+    RT_NOREF2(DeviceName, Context);
     vboxNetFltWinNotifyHostAddress(Address, false);
 }
@@ -3444,5 +3445,5 @@
             Assert(!g_VBoxNetFltGlobalsWin.hNotifier);
             NTSTATUS Status = TdiRegisterPnPHandlers(&Info, sizeof(Info), &g_VBoxNetFltGlobalsWin.hNotifier);
-            Log2(("vboxNetFltWinRegisterIpAddrNotifier: TdiRegisterPnPHandlers returned %d\n", Status));
+            Log2(("vboxNetFltWinRegisterIpAddrNotifier: TdiRegisterPnPHandlers returned %d\n", Status)); NOREF(Status);
         }
         else
@@ -3487,5 +3488,5 @@
             NTSTATUS Status = TdiDeregisterPnPHandlers(hNotifier);
             Log2(("vboxNetFltWinUnregisterIpAddrNotifier: TdiDeregisterPnPHandlers(%p) returned %d\n",
-                  hNotifier, Status));
+                  hNotifier, Status)); NOREF(Status);
         }
         else
@@ -3612,4 +3613,5 @@
 void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac)
 {
+    RT_NOREF3(pThis, pvIfData, pMac);
 }
 
@@ -3617,4 +3619,5 @@
 {
     /* Nothing to do */
+    RT_NOREF3(pThis, pvIf, ppvIfData);
     return VINF_SUCCESS;
 }
@@ -3623,4 +3626,5 @@
 {
     /* Nothing to do */
+    RT_NOREF2(pThis, pvIfData);
     return VINF_SUCCESS;
 }
