Author: tkreuzer
Date: Mon Dec 17 12:06:14 2012
New Revision: 57936
URL:
http://svn.reactos.org/svn/reactos?rev=57936&view=rev
Log:
[RTL]
- 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
Modified:
trunk/reactos/lib/rtl/actctx.c
trunk/reactos/lib/rtl/dbgbuffer.c
trunk/reactos/lib/rtl/heap.c
trunk/reactos/lib/rtl/i386/except.c
trunk/reactos/lib/rtl/ppb.c
trunk/reactos/lib/rtl/rangelist.c
trunk/reactos/lib/rtl/registry.c
trunk/reactos/lib/rtl/srw.c
trunk/reactos/lib/rtl/version.c
trunk/reactos/lib/rtl/workitem.c
Modified: trunk/reactos/lib/rtl/actctx.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/actctx.c?rev=57936…
==============================================================================
--- trunk/reactos/lib/rtl/actctx.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/actctx.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -192,7 +192,7 @@
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 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 @@
{',','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 @@
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 @@
{
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 @@
{
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 @@
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 @@
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 @@
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 @@
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;
Modified: trunk/reactos/lib/rtl/dbgbuffer.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/dbgbuffer.c?rev=57…
==============================================================================
--- trunk/reactos/lib/rtl/dbgbuffer.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/dbgbuffer.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -260,7 +260,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
Modified: trunk/reactos/lib/rtl/heap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heap.c?rev=57936&a…
==============================================================================
--- trunk/reactos/lib/rtl/heap.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heap.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -2761,7 +2761,7 @@
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)
{
Modified: trunk/reactos/lib/rtl/i386/except.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/i386/except.c?rev=…
==============================================================================
--- trunk/reactos/lib/rtl/i386/except.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/i386/except.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -33,7 +33,7 @@
/* 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 @@
/* 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 @@
/* 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 @@
RegistrationFrame,
Context,
&DispatcherContext,
- RegistrationFrame->
- Handler);
+ RegistrationFrame->Handler);
/* Check if this is a nested frame */
if (RegistrationFrame == NestedFrame)
@@ -274,6 +276,9 @@
/* 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 @@
RegistrationFrame,
Context,
&DispatcherContext,
- RegistrationFrame->
- Handler);
+ RegistrationFrame->Handler);
switch(Disposition)
{
/* Continue searching */
Modified: trunk/reactos/lib/rtl/ppb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/ppb.c?rev=57936&am…
==============================================================================
--- trunk/reactos/lib/rtl/ppb.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/ppb.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -147,8 +147,6 @@
/* 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'\\')
{
Modified: trunk/reactos/lib/rtl/rangelist.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/rangelist.c?rev=57…
==============================================================================
--- trunk/reactos/lib/rtl/rangelist.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/rangelist.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -569,12 +569,6 @@
PRTL_RANGE_ENTRY Current;
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;
@@ -618,6 +612,13 @@
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)
{
Modified: trunk/reactos/lib/rtl/registry.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/registry.c?rev=579…
==============================================================================
--- trunk/reactos/lib/rtl/registry.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/registry.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -10,6 +10,8 @@
/* INCLUDES *****************************************************************/
#include <rtl.h>
+#include <suppress.h>
+
#define NDEBUG
#include <debug.h>
@@ -242,6 +244,7 @@
{
/* 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 @@
KeyInfo,
BufferLength,
&ReturnedLength);
- if (NT_SUCCESS(Status))
+ if (NT_SUCCESS(Status) && (KeyInfo != NULL))
{
/* Check if the name fits */
if (KeyInfo->NameLength <= SubKeyName->MaximumLength)
Modified: trunk/reactos/lib/rtl/srw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/srw.c?rev=57936&am…
==============================================================================
--- trunk/reactos/lib/rtl/srw.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/srw.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -140,19 +140,19 @@
}
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);
}
}
Modified: trunk/reactos/lib/rtl/version.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/version.c?rev=5793…
==============================================================================
--- trunk/reactos/lib/rtl/version.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/version.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -214,6 +214,8 @@
IN DWORD dwTypeBitMask,
IN BYTE bConditionMask)
{
+ ULONGLONG ullCondMask;
+
if (dwTypeBitMask == 0)
return dwlConditionMask;
@@ -222,22 +224,23 @@
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;
}
Modified: trunk/reactos/lib/rtl/workitem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/workitem.c?rev=579…
==============================================================================
--- trunk/reactos/lib/rtl/workitem.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/workitem.c [iso-8859-1] Mon Dec 17 12:06:14 2012
@@ -175,7 +175,7 @@
if (NT_SUCCESS(Status))
{
NtResumeThread(ThreadHandle, NULL);
-
+
/* Poll until the thread got a chance to initialize */
while (WorkerInitialized == 0)
{
@@ -724,6 +724,7 @@
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
+ (void)0;
}
_SEH2_END;
}