[RTL]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 17 Dec 2012 12:06:14 +0000 (12:06 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 17 Dec 2012 12:06:14 +0000 (12:06 +0000)
- Fix a calculation bug in the heap code
- Fix pointer arithmetics
- Fix artihetic overflows
- rename some global items to not conflict with local names
- Silence some more warnings from VS analyze

svn path=/trunk/; revision=57936

reactos/lib/rtl/actctx.c
reactos/lib/rtl/dbgbuffer.c
reactos/lib/rtl/heap.c
reactos/lib/rtl/i386/except.c
reactos/lib/rtl/ppb.c
reactos/lib/rtl/rangelist.c
reactos/lib/rtl/registry.c
reactos/lib/rtl/srw.c
reactos/lib/rtl/version.c
reactos/lib/rtl/workitem.c

index fe94e5a..0d55e03 100644 (file)
@@ -192,7 +192,7 @@ static const WCHAR helpdirW[] = {'h','e','l','p','d','i','r',0};
 static const WCHAR iidW[] = {'i','i','d',0};
 static const WCHAR languageW[] = {'l','a','n','g','u','a','g','e',0};
 static const WCHAR manifestVersionW[] = {'m','a','n','i','f','e','s','t','V','e','r','s','i','o','n',0};
-static const WCHAR nameW[] = {'n','a','m','e',0};
+static const WCHAR g_nameW[] = {'n','a','m','e',0};
 static const WCHAR newVersionW[] = {'n','e','w','V','e','r','s','i','o','n',0};
 static const WCHAR oldVersionW[] = {'o','l','d','V','e','r','s','i','o','n',0};
 static const WCHAR optionalW[] = {'o','p','t','i','o','n','a','l',0};
@@ -203,7 +203,7 @@ static const WCHAR typeW[] = {'t','y','p','e',0};
 static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0};
 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
 
-static const WCHAR xmlW[] = {'?','x','m','l',0};
+static const WCHAR g_xmlW[] = {'?','x','m','l',0};
 static const WCHAR manifestv1W[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','1',0};
 static const WCHAR manifestv3W[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','3',0};
 
@@ -528,21 +528,17 @@ static WCHAR *build_assembly_id( const struct assembly_identity *ai )
         {',','p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e','=',0};
     static const WCHAR public_keyW[] =
         {',','p','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
-    static const WCHAR typeW[] =
-        {',','t','y','p','e','=',0};
-    static const WCHAR versionW[] =
-        {',','v','e','r','s','i','o','n','=',0};
 
     WCHAR version[64], *ret;
     SIZE_T size = 0;
 
     sprintfW( version, version_formatW,
               ai->version.major, ai->version.minor, ai->version.build, ai->version.revision );
-    if (ai->name) size += strlenW(ai->name) * sizeof(WCHAR);
+    if (ai->name) size += strlenW(ai->name);
     if (ai->arch) size += strlenW(archW) + strlenW(ai->arch) + 2;
     if (ai->public_key) size += strlenW(public_keyW) + strlenW(ai->public_key) + 2;
-    if (ai->type) size += strlenW(typeW) + strlenW(ai->type) + 2;
-    size += strlenW(versionW) + strlenW(version) + 2;
+    if (ai->type) size += 1 + strlenW(typeW) + 1 + strlenW(ai->type) + 2;
+    size += 1+ strlenW(versionW) + 1 + strlenW(version) + 2;
 
     if (!(ret = RtlAllocateHeap( RtlGetProcessHeap(), 0, (size + 1) * sizeof(WCHAR) )))
         return NULL;
@@ -847,7 +843,7 @@ static BOOL parse_assembly_identity_elem(xmlbuf_t* xmlbuf, ACTIVATION_CONTEXT* a
 
     while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
     {
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(ai->name = xmlstrdupW(&attr_value))) return FALSE;
         }
@@ -944,7 +940,7 @@ static BOOL parse_cominterface_proxy_stub_elem(xmlbuf_t* xmlbuf, struct dll_redi
         {
             if (!(entity->u.proxy.iid = xmlstrdupW(&attr_value))) return FALSE;
         }
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(entity->u.proxy.name = xmlstrdupW(&attr_value))) return FALSE;
         }
@@ -1107,7 +1103,7 @@ static BOOL parse_com_interface_external_proxy_stub_elem(xmlbuf_t* xmlbuf,
         {
             if (!(entity->u.proxy.iid = xmlstrdupW(&attr_value))) return FALSE;
         }
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(entity->u.proxy.name = xmlstrdupW(&attr_value))) return FALSE;
         }
@@ -1133,7 +1129,7 @@ static BOOL parse_clr_class_elem(xmlbuf_t* xmlbuf, struct assembly* assembly)
 
     while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
     {
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(entity->u.clrclass.name = xmlstrdupW(&attr_value))) return FALSE;
         }
@@ -1165,7 +1161,7 @@ static BOOL parse_clr_surrogate_elem(xmlbuf_t* xmlbuf, struct assembly* assembly
 
     while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
     {
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(entity->u.clrsurrogate.name = xmlstrdupW(&attr_value))) return FALSE;
         }
@@ -1299,7 +1295,7 @@ static BOOL parse_file_elem(xmlbuf_t* xmlbuf, struct assembly* assembly)
         attr_nameU = xmlstr2unicode(&attr_name);
         attr_valueU = xmlstr2unicode(&attr_value);
 
-        if (xmlstr_cmp(&attr_name, nameW))
+        if (xmlstr_cmp(&attr_name, g_nameW))
         {
             if (!(dll->name = xmlstrdupW(&attr_value))) return FALSE;
             DPRINT("name=%wZ\n", &attr_valueU);
@@ -1499,7 +1495,7 @@ static NTSTATUS parse_manifest_buffer( struct actctx_loader* acl, struct assembl
 
     if (!next_xml_elem(xmlbuf, &elem)) return STATUS_SXS_CANT_GEN_ACTCTX;
 
-    if (xmlstr_cmp(&elem, xmlW) &&
+    if (xmlstr_cmp(&elem, g_xmlW) &&
         (!parse_xml_header(xmlbuf) || !next_xml_elem(xmlbuf, &elem)))
         return STATUS_SXS_CANT_GEN_ACTCTX;
 
index cf71683..f65ae6f 100644 (file)
@@ -260,7 +260,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 ULONG ReturnSize = 0;
                 ULONG MSize;
 
-                Mp = (PRTL_PROCESS_MODULES)(Buf + Buf->OffsetFree);
+                Mp = (PRTL_PROCESS_MODULES)((PUCHAR)Buf + Buf->OffsetFree);
 
                 /* I like this better than the do & while loop. */
                 Status = LdrQueryProcessModuleInformation(NULL,
@@ -284,7 +284,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 PRTL_PROCESS_HEAPS Hp;
                 ULONG HSize;
 
-                Hp = (PRTL_PROCESS_HEAPS)(Buf + Buf->OffsetFree);
+                Hp = (PRTL_PROCESS_HEAPS)((PUCHAR)Buf + Buf->OffsetFree);
                 HSize = sizeof(RTL_PROCESS_HEAPS);
                 if (DebugInfoMask & RTL_DEBUG_QUERY_HEAP_TAGS)
                 {
@@ -304,7 +304,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 PRTL_PROCESS_LOCKS Lp;
                 ULONG LSize;
 
-                Lp = (PRTL_PROCESS_LOCKS)(Buf + Buf->OffsetFree);
+                Lp = (PRTL_PROCESS_LOCKS)((PUCHAR)Buf + Buf->OffsetFree);
                 LSize = sizeof(RTL_PROCESS_LOCKS);
                 Buf->Locks = Lp;
                 Buf->OffsetFree = Buf->OffsetFree + LSize;
@@ -344,7 +344,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 ULONG ReturnSize = 0;
                 ULONG MSize;
 
-                Mp = (PRTL_PROCESS_MODULES)(Buf + Buf->OffsetFree);
+                Mp = (PRTL_PROCESS_MODULES)((PUCHAR)Buf + Buf->OffsetFree);
 
                 Status = RtlpQueryRemoteProcessModules(hProcess,
                                                        NULL,
@@ -370,7 +370,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 PRTL_PROCESS_HEAPS Hp;
                 ULONG HSize;
 
-                Hp = (PRTL_PROCESS_HEAPS)(Buf + Buf->OffsetFree);
+                Hp = (PRTL_PROCESS_HEAPS)((PUCHAR)Buf + Buf->OffsetFree);
                 HSize = sizeof(RTL_PROCESS_HEAPS);
                 if (DebugInfoMask & RTL_DEBUG_QUERY_HEAP_TAGS)
                 {
@@ -390,7 +390,7 @@ RtlQueryProcessDebugInformation(IN ULONG ProcessId,
                 PRTL_PROCESS_LOCKS Lp;
                 ULONG LSize;
 
-                Lp = (PRTL_PROCESS_LOCKS)(Buf + Buf->OffsetFree);
+                Lp = (PRTL_PROCESS_LOCKS)((PUCHAR)Buf + Buf->OffsetFree);
                 LSize = sizeof(RTL_PROCESS_LOCKS);
                 Buf->Locks = Lp;
                 Buf->OffsetFree = Buf->OffsetFree + LSize;
index 6c6e0d2..6d0161c 100644 (file)
@@ -2761,7 +2761,7 @@ RtlReAllocateHeap(HANDLE HeapPtr,
         if (InUseEntry->Flags & HEAP_ENTRY_VIRTUAL_ALLOC)
         {
             /* Simple in case of a virtual alloc - just an unused size */
-            InUseEntry->Size = (USHORT)(AllocationSize - Size);
+            InUseEntry->Size = (USHORT)((AllocationSize - Size) >> HEAP_ENTRY_SHIFT);
         }
         else if (InUseEntry->Flags & HEAP_ENTRY_EXTRA_PRESENT)
         {
index 66a9d81..0165fff 100644 (file)
@@ -33,7 +33,7 @@ RtlGetCallersAddress(OUT PVOID *CallersAddress,
     /* Only if user want it */
     if (*CallersAddress != NULL)
     {
-        /* only when first frames exist */ 
+        /* only when first frames exist */
         if (FrameCount >= 1)
         {
             *CallersAddress = BackTrace[0];
@@ -47,7 +47,7 @@ RtlGetCallersAddress(OUT PVOID *CallersAddress,
     /* Only if user want it */
     if (*CallersCaller != NULL)
     {
-        /* only when second frames exist */ 
+        /* only when second frames exist */
         if (FrameCount >= 2)
         {
             *CallersCaller = BackTrace[1];
@@ -92,6 +92,9 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
     /* Now loop every frame */
     while (RegistrationFrame != EXCEPTION_CHAIN_END)
     {
+        /* Registration chain entries are never NULL */
+        ASSERT(RegistrationFrame != NULL);
+
         /* Find out where it ends */
         RegistrationFrameEnd = (ULONG_PTR)RegistrationFrame +
                                 sizeof(EXCEPTION_REGISTRATION_RECORD);
@@ -127,8 +130,7 @@ RtlDispatchException(IN PEXCEPTION_RECORD ExceptionRecord,
                                                      RegistrationFrame,
                                                      Context,
                                                      &DispatcherContext,
-                                                     RegistrationFrame->
-                                                     Handler);
+                                                     RegistrationFrame->Handler);
 
         /* Check if this is a nested frame */
         if (RegistrationFrame == NestedFrame)
@@ -274,6 +276,9 @@ RtlUnwind(IN PVOID TargetFrame OPTIONAL,
     /* Now loop every frame */
     while (RegistrationFrame != EXCEPTION_CHAIN_END)
     {
+        /* Registration chain entries are never NULL */
+        ASSERT(RegistrationFrame != NULL);
+
         /* If this is the target */
         if (RegistrationFrame == TargetFrame) ZwContinue(Context, FALSE);
 
@@ -326,8 +331,7 @@ RtlUnwind(IN PVOID TargetFrame OPTIONAL,
                                                       RegistrationFrame,
                                                       Context,
                                                       &DispatcherContext,
-                                                      RegistrationFrame->
-                                                      Handler);
+                                                      RegistrationFrame->Handler);
             switch(Disposition)
             {
                 /* Continue searching */
index 7b22139..17b4ffa 100644 (file)
@@ -147,8 +147,6 @@ RtlCreateProcessParameters(PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
    /* make sure the current directory has a trailing backslash */
    if (Param->CurrentDirectory.DosPath.Length > 0)
      {
-       ULONG Length;
-
        Length = Param->CurrentDirectory.DosPath.Length / sizeof(WCHAR);
        if (Param->CurrentDirectory.DosPath.Buffer[Length-1] != L'\\')
          {
index a2f5664..1b8c794 100644 (file)
@@ -570,12 +570,6 @@ RtlInvertRangeList(OUT PRTL_RANGE_LIST InvertedRangeList,
     PLIST_ENTRY Entry;
     NTSTATUS Status;
 
-    /* Don't invert an empty range list */
-    if (IsListEmpty(&RangeList->ListHead))
-    {
-        return STATUS_SUCCESS;
-    }
-
     /* Add leading and intermediate ranges */
     Previous = NULL;
     Entry = RangeList->ListHead.Flink;
@@ -618,6 +612,13 @@ RtlInvertRangeList(OUT PRTL_RANGE_LIST InvertedRangeList,
         Entry = Entry->Flink;
     }
 
+    /* Check if the list was empty */
+    if (Previous == NULL)
+    {
+        /* We're done */
+        return STATUS_SUCCESS;
+    }
+
     /* Add trailing range */
     if (Previous->Range.End + 1 != (ULONGLONG)-1)
     {
index 434946f..79230a1 100644 (file)
@@ -10,6 +10,8 @@
 /* INCLUDES *****************************************************************/
 
 #include <rtl.h>
+#include <suppress.h>
+
 #define NDEBUG
 #include <debug.h>
 
@@ -242,6 +244,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
         {
             /* Prepare defaults */
             Status = STATUS_SUCCESS;
+            _PRAGMA_WARNING_SUPPRESS(__WARNING_SIZEOF_COUNTOF_MISMATCH)
             ValueEnd = (PWSTR)((ULONG_PTR)Data + Length) - sizeof(UNICODE_NULL);
             p = Data;
 
@@ -834,7 +837,7 @@ RtlpNtEnumerateSubKey(IN HANDLE KeyHandle,
                             KeyInfo,
                             BufferLength,
                             &ReturnedLength);
-    if (NT_SUCCESS(Status))
+    if (NT_SUCCESS(Status) && (KeyInfo != NULL))
     {
         /* Check if the name fits */
         if (KeyInfo->NameLength <= SubKeyName->MaximumLength)
index 48ad351..782a2f4 100644 (file)
@@ -140,19 +140,19 @@ RtlpReleaseWaitBlockLockExclusive(IN OUT PRTL_SRWLOCK SRWLock,
     }
     else
     {
-        PRTLP_SRWLOCK_SHARED_WAKE WakeChain, Next;
+        PRTLP_SRWLOCK_SHARED_WAKE WakeChain, NextWake;
 
         /* If we were the first one to acquire the shared
            lock, we now need to wake all others... */
         WakeChain = FirstWaitBlock->SharedWakeChain;
         do
         {
-            Next = WakeChain->Next;
+            NextWake = WakeChain->Next;
 
             (void)InterlockedOr((PLONG)&WakeChain->Wake,
                                 TRUE);
 
-            WakeChain = Next;
+            WakeChain = NextWake;
         } while (WakeChain != NULL);
     }
 }
index b2e8210..d340380 100644 (file)
@@ -214,6 +214,8 @@ VerSetConditionMask(IN ULONGLONG dwlConditionMask,
                     IN DWORD dwTypeBitMask,
                     IN BYTE bConditionMask)
 {
+    ULONGLONG ullCondMask;
+
     if (dwTypeBitMask == 0)
         return dwlConditionMask;
 
@@ -222,22 +224,23 @@ VerSetConditionMask(IN ULONGLONG dwlConditionMask,
     if (bConditionMask == 0)
         return dwlConditionMask;
 
+    ullCondMask = bConditionMask;
     if (dwTypeBitMask & VER_PRODUCT_TYPE)
-        dwlConditionMask |= bConditionMask << 7 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (7 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_SUITENAME)
-        dwlConditionMask |= bConditionMask << 6 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (6 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_SERVICEPACKMAJOR)
-        dwlConditionMask |= bConditionMask << 5 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (5 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_SERVICEPACKMINOR)
-        dwlConditionMask |= bConditionMask << 4 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (4 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_PLATFORMID)
-        dwlConditionMask |= bConditionMask << 3 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (3 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_BUILDNUMBER)
-        dwlConditionMask |= bConditionMask << 2 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (2 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_MAJORVERSION)
-        dwlConditionMask |= bConditionMask << 1 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (1 * VER_NUM_BITS_PER_CONDITION_MASK);
     else if (dwTypeBitMask & VER_MINORVERSION)
-        dwlConditionMask |= bConditionMask << 0 * VER_NUM_BITS_PER_CONDITION_MASK;
+        dwlConditionMask |= ullCondMask << (0 * VER_NUM_BITS_PER_CONDITION_MASK);
 
     return dwlConditionMask;
 }
index f337713..5d4fae0 100644 (file)
@@ -175,7 +175,7 @@ RtlpStartWorkerThread(PTHREAD_START_ROUTINE StartRoutine)
     if (NT_SUCCESS(Status))
     {
         NtResumeThread(ThreadHandle, NULL);
-        
+
         /* Poll until the thread got a chance to initialize */
         while (WorkerInitialized == 0)
         {
@@ -724,6 +724,7 @@ RtlpWorkerThreadProc(IN PVOID Parameter)
             }
             _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
             {
+                (void)0;
             }
             _SEH2_END;
         }