mirror of
https://github.com/reactos/reactos.git
synced 2024-12-31 19:42:51 +00:00
[RTL]
- Fix possible integer overflow in RtlpInitializeHeapSegment - Simplify loop in RtlIsDosDeviceName_Ustr - Make MonthLengths an array of UCHARs instead of ints - Remove pointless loops in RtlTimeToTimeFields - Fix MSVC warnings svn path=/trunk/; revision=54054
This commit is contained in:
parent
56e0a450bd
commit
0fa1475dfd
6 changed files with 31 additions and 45 deletions
|
@ -1794,7 +1794,7 @@ static NTSTATUS get_manifest_in_manifest_file( struct actctx_loader* acl, struct
|
|||
status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileStandardInformation);
|
||||
|
||||
if (status == STATUS_SUCCESS)
|
||||
status = parse_manifest(acl, ai, filename, directory, shared, base, info.EndOfFile.QuadPart);
|
||||
status = parse_manifest(acl, ai, filename, directory, shared, base, (SIZE_T)info.EndOfFile.QuadPart);
|
||||
|
||||
NtUnmapViewOfSection( NtCurrentProcess(), base );
|
||||
NtClose( mapping );
|
||||
|
|
|
@ -913,9 +913,9 @@ RtlpInitializeHeapSegment(IN OUT PHEAP Heap,
|
|||
|
||||
/* Initialise the Heap Entries contained within the Heap Segment */
|
||||
Segment->FirstEntry = &Segment->Entry + Segment->Entry.Size;
|
||||
Segment->LastValidEntry = (PHEAP_ENTRY) ((ULONG_PTR) (Segment) + SegmentReserve);
|
||||
Segment->LastValidEntry = (PHEAP_ENTRY)((ULONG_PTR)Segment + SegmentReserve);
|
||||
|
||||
if ((Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit)
|
||||
if (((SIZE_T)Segment->Entry.Size << HEAP_ENTRY_SHIFT) < SegmentCommit)
|
||||
{
|
||||
HeapEntry = Segment->FirstEntry;
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString)
|
|||
{
|
||||
UNICODE_STRING PathCopy;
|
||||
PWCHAR Start, End;
|
||||
ULONG PathChars, ColonCount = 0;
|
||||
USHORT PathChars, ColonCount = 0;
|
||||
USHORT ReturnOffset = 0, ReturnLength;
|
||||
WCHAR c;
|
||||
|
||||
|
@ -94,19 +94,18 @@ RtlIsDosDeviceName_Ustr(IN PUNICODE_STRING PathString)
|
|||
}
|
||||
|
||||
/* Check for extension or space, and truncate */
|
||||
c = PathCopy.Buffer[PathChars - 1];
|
||||
do
|
||||
{
|
||||
/* Stop if we hit something else than a space or period */
|
||||
c = PathCopy.Buffer[PathChars - 1];
|
||||
if ((c != '.') && (c != ' ')) break;
|
||||
|
||||
/* Fixup the lengths and get the next character */
|
||||
/* Fixup the lengths */
|
||||
PathCopy.Length -= sizeof(WCHAR);
|
||||
if (--PathChars) c = PathCopy.Buffer[PathChars - 1];
|
||||
|
||||
/* Remember this for later */
|
||||
ColonCount++;
|
||||
} while (PathChars);
|
||||
} while (--PathChars);
|
||||
|
||||
/* Anything still left? */
|
||||
if (PathChars)
|
||||
|
|
|
@ -118,7 +118,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
|
|||
{
|
||||
ULONG InfoLength;
|
||||
SIZE_T Length, SpareLength, c;
|
||||
LONG RequiredLength;
|
||||
ULONG RequiredLength;
|
||||
PCHAR SpareData, DataEnd;
|
||||
ULONG Type;
|
||||
PWCHAR Name, p, ValueEnd;
|
||||
|
@ -341,7 +341,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
|
|||
Status = RtlExpandEnvironmentStrings_U(Environment,
|
||||
&Source,
|
||||
&Destination,
|
||||
(PULONG)&RequiredLength);
|
||||
&RequiredLength);
|
||||
Type = REG_SZ;
|
||||
|
||||
/* Check for success */
|
||||
|
|
|
@ -38,14 +38,14 @@
|
|||
|
||||
|
||||
static const int YearLengths[2] =
|
||||
{
|
||||
DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
|
||||
};
|
||||
static const int MonthLengths[2][MONSPERYEAR] =
|
||||
{
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
{
|
||||
DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
|
||||
};
|
||||
static const UCHAR MonthLengths[2][MONSPERYEAR] =
|
||||
{
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
|
||||
static __inline int IsLeapYear(int Year)
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
|
|||
TIME_FIELDS CurrentTimeFields;
|
||||
TIME_FIELDS CutoverSystemTimeFields;
|
||||
LARGE_INTEGER CutoverSystemTime;
|
||||
CSHORT MonthLength;
|
||||
UCHAR MonthLength;
|
||||
CSHORT Days;
|
||||
BOOLEAN NextYearsCutover = FALSE;
|
||||
|
||||
|
@ -255,32 +255,20 @@ RtlTimeToTimeFields(
|
|||
IN PLARGE_INTEGER Time,
|
||||
OUT PTIME_FIELDS TimeFields)
|
||||
{
|
||||
const int *Months;
|
||||
int SecondsInDay, CurYear;
|
||||
int LeapYear, CurMonth;
|
||||
long int Days;
|
||||
LONGLONG IntTime = (LONGLONG)Time->QuadPart;
|
||||
const UCHAR *Months;
|
||||
ULONG SecondsInDay, CurYear;
|
||||
ULONG LeapYear, CurMonth;
|
||||
ULONG Days;
|
||||
ULONGLONG IntTime = Time->QuadPart;
|
||||
|
||||
/* Extract millisecond from time and convert time into seconds */
|
||||
TimeFields->Milliseconds = (CSHORT) ((IntTime % TICKSPERSEC) / TICKSPERMSEC);
|
||||
IntTime = IntTime / TICKSPERSEC;
|
||||
|
||||
/* Split the time into days and seconds within the day */
|
||||
Days = IntTime / SECSPERDAY;
|
||||
Days = (ULONG)(IntTime / SECSPERDAY);
|
||||
SecondsInDay = IntTime % SECSPERDAY;
|
||||
|
||||
/* Adjust the values for days and seconds in day */
|
||||
while (SecondsInDay < 0)
|
||||
{
|
||||
SecondsInDay += SECSPERDAY;
|
||||
Days--;
|
||||
}
|
||||
while (SecondsInDay >= SECSPERDAY)
|
||||
{
|
||||
SecondsInDay -= SECSPERDAY;
|
||||
Days++;
|
||||
}
|
||||
|
||||
/* compute time of day */
|
||||
TimeFields->Hour = (CSHORT) (SecondsInDay / SECSPERHOUR);
|
||||
SecondsInDay = SecondsInDay % SECSPERHOUR;
|
||||
|
@ -297,20 +285,20 @@ RtlTimeToTimeFields(
|
|||
while (1)
|
||||
{
|
||||
LeapYear = IsLeapYear(CurYear);
|
||||
if (Days < (long) YearLengths[LeapYear])
|
||||
if (Days < YearLengths[LeapYear])
|
||||
{
|
||||
break;
|
||||
}
|
||||
CurYear++;
|
||||
Days = Days - (long) YearLengths[LeapYear];
|
||||
Days = Days - YearLengths[LeapYear];
|
||||
}
|
||||
TimeFields->Year = (CSHORT) CurYear;
|
||||
|
||||
/* Compute month of year */
|
||||
LeapYear = IsLeapYear(CurYear);
|
||||
Months = MonthLengths[LeapYear];
|
||||
for (CurMonth = 0; Days >= (long) Months[CurMonth]; CurMonth++)
|
||||
Days = Days - (long) Months[CurMonth];
|
||||
for (CurMonth = 0; Days >= Months[CurMonth]; CurMonth++)
|
||||
Days = Days - Months[CurMonth];
|
||||
TimeFields->Month = (CSHORT) (CurMonth + 1);
|
||||
TimeFields->Day = (CSHORT) (Days + 1);
|
||||
}
|
||||
|
|
|
@ -2495,8 +2495,7 @@ RtlFindCharInUnicodeString(
|
|||
IN PCUNICODE_STRING MatchString,
|
||||
OUT PUSHORT Position)
|
||||
{
|
||||
SHORT i;
|
||||
USHORT j;
|
||||
USHORT i, j;
|
||||
|
||||
switch (Flags)
|
||||
{
|
||||
|
@ -2520,7 +2519,7 @@ RtlFindCharInUnicodeString(
|
|||
|
||||
case 1:
|
||||
{
|
||||
for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--)
|
||||
for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
|
||||
{
|
||||
for (j = 0; j < MatchString->Length / sizeof(WCHAR); j++)
|
||||
{
|
||||
|
@ -2561,7 +2560,7 @@ RtlFindCharInUnicodeString(
|
|||
|
||||
case 3:
|
||||
{
|
||||
for (i = SearchString->Length / sizeof(WCHAR) - 1; i >= 0; i--)
|
||||
for (i = SearchString->Length / sizeof(WCHAR) - 1; (i + 1) > 0; i--)
|
||||
{
|
||||
j = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue