Various fixes to the existing routines:
All checks were successful
ci/woodpecker/push/build Pipeline was successful

* Export RtlWideStringTokenize()
 * Allow to compare whole strings in RtlWideStringCompare() when no length specified
 * RtlSameMemory() returns boolean now
 * Source bytes can be constant value in RtlCopyMemory()
This commit is contained in:
Rafal Kupiec 2022-09-05 15:17:12 +02:00
parent 8a91412ec4
commit d56b10f252
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
4 changed files with 30 additions and 22 deletions

View File

@ -15,7 +15,7 @@
XTAPI XTAPI
PVOID VOID
RtlCopyMemory(IN PVOID Destination, RtlCopyMemory(IN PVOID Destination,
IN PCVOID Source, IN PCVOID Source,
IN SIZE_T Length); IN SIZE_T Length);
@ -38,16 +38,18 @@ BOOLEAN
RtlListEmpty(PLIST_ENTRY ListHead); RtlListEmpty(PLIST_ENTRY ListHead);
XTAPI XTAPI
SIZE_T BOOLEAN
RtlSameMemory(IN PCVOID LeftBuffer, RtlSameMemory(IN PCVOID LeftBuffer,
IN PCVOID RightBuffer, IN PCVOID RightBuffer,
IN SIZE_T Length); IN SIZE_T Length);
XTCDECL
INT INT
RtlWideStringCompare(IN CONST PWCHAR String1, RtlWideStringCompare(IN CONST PWCHAR String1,
IN CONST PWCHAR String2, IN CONST PWCHAR String2,
IN CONST ULONG Length); IN CONST ULONG Length);
XTCDECL
PWCHAR PWCHAR
RtlWideStringTokenize(IN PWCHAR String, RtlWideStringTokenize(IN PWCHAR String,
IN CONST PWCHAR Delimiter, IN CONST PWCHAR Delimiter,

View File

@ -21,27 +21,24 @@
* @param Length * @param Length
* Specifies the number of bytes to copy. * Specifies the number of bytes to copy.
* *
* @return Returns the destination pointer. * @return This routine does not return any value.
* *
* @since NT 3.5 * @since NT 3.5
*/ */
XTAPI XTAPI
PVOID VOID
RtlCopyMemory(IN PVOID Destination, RtlCopyMemory(IN PVOID Destination,
IN PCVOID Source, IN PCVOID Source,
IN SIZE_T Length) IN SIZE_T Length)
{ {
PCHAR DestinationBytes = (PCHAR)Destination; PCHAR DestinationBytes = (PCHAR)Destination;
PCHAR SourceBytes = (PCHAR)Source; PCCHAR SourceBytes = (PCHAR)Source;
/* Forward buffer copy */ /* Forward buffer copy */
while(Length--) while(Length--)
{ {
*DestinationBytes++ = *SourceBytes++; *DestinationBytes++ = *SourceBytes++;
} }
/* Return pointer to destination buffer */
return Destination;
} }
/** /**
@ -56,20 +53,18 @@ RtlCopyMemory(IN PVOID Destination,
* @param Length * @param Length
* Specifies a number of bytes to compare. * Specifies a number of bytes to compare.
* *
* @return A value indicating the relationship between the content of the memory blocks. * @return Returns TRUE if both buffers are equal up to the specified length, or FALSE otherwise.
* It returns zero (0) if both memory blocks are equal or a value different than
* zero representing which is greater if they do not match.
* *
* @since XT 1.0 * @since XT 1.0
*/ */
XTAPI XTAPI
SIZE_T BOOLEAN
RtlSameMemory(IN PCVOID LeftBuffer, RtlSameMemory(IN PCVOID LeftBuffer,
IN PCVOID RightBuffer, IN PCVOID RightBuffer,
IN SIZE_T Length) IN SIZE_T Length)
{ {
CONST UCHAR *Left = (PUCHAR)LeftBuffer; CONST CHAR *Left = (PCHAR)LeftBuffer;
CONST UCHAR *Right = (PUCHAR)RightBuffer; CONST CHAR *Right = (PCHAR)RightBuffer;
/* Check if there is anything to compare */ /* Check if there is anything to compare */
if(Length) if(Length)
@ -81,7 +76,7 @@ RtlSameMemory(IN PCVOID LeftBuffer,
if(*Left != *Right) if(*Left != *Right)
{ {
/* Buffers differ */ /* Buffers differ */
return (*Left - *Right); return FALSE;
} }
/* Advance to next byte */ /* Advance to next byte */
@ -91,5 +86,5 @@ RtlSameMemory(IN PCVOID LeftBuffer,
} }
/* Buffers equal */ /* Buffers equal */
return 0; return TRUE;
} }

View File

@ -25,6 +25,7 @@
* *
* @since XT 1.0 * @since XT 1.0
*/ */
XTCDECL
INT INT
RtlWideStringCompare(IN CONST PWCHAR String1, RtlWideStringCompare(IN CONST PWCHAR String1,
IN CONST PWCHAR String2, IN CONST PWCHAR String2,
@ -33,7 +34,14 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
ULONG Index; ULONG Index;
/* Iterate through the strings */ /* Iterate through the strings */
for(Index = 0; Index < Length; Index++) { for(Index = 0; ; Index++) {
/* Check if length limit reached */
if(Index != 0 && Index == Length)
{
/* Skip checking next characters */
break;
}
/* Check if string characters are equal */ /* Check if string characters are equal */
if(String1[Index] != String2[Index]) if(String1[Index] != String2[Index])
{ {
@ -42,9 +50,9 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
} }
/* Check if end of string reached */ /* Check if end of string reached */
if(!String1[Index]) if(!String1[Index] || !String2[Index])
{ {
/* Equal strings until the end of String1 */ /* Equal strings until the end of one of them */
return 0; return 0;
} }
} }
@ -69,6 +77,7 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
* *
* @since: XT 1.0 * @since: XT 1.0
*/ */
XTCDECL
PWCHAR PWCHAR
RtlWideStringTokenize(IN PWCHAR String, RtlWideStringTokenize(IN PWCHAR String,
IN CONST PWCHAR Delimiter, IN CONST PWCHAR Delimiter,
@ -81,7 +90,7 @@ RtlWideStringTokenize(IN PWCHAR String,
if(String == NULL && (String = *SavePtr) == NULL) if(String == NULL && (String = *SavePtr) == NULL)
{ {
/* Empty string given */ /* Empty string given */
return (NULL); return NULL;
} }
/* Check non-delimiter characters */ /* Check non-delimiter characters */
@ -89,7 +98,7 @@ RtlWideStringTokenize(IN PWCHAR String,
if(Char == L'\0') if(Char == L'\0')
{ {
*SavePtr = NULL; *SavePtr = NULL;
return (NULL); return NULL;
} }
Token = String - 1; Token = String - 1;
@ -110,6 +119,7 @@ RtlWideStringTokenize(IN PWCHAR String,
{ {
String[-1] = L'\0'; String[-1] = L'\0';
} }
/* Store pointer to the next token */ /* Store pointer to the next token */
*SavePtr = String; *SavePtr = String;

View File

@ -2,4 +2,5 @@
@ stdcall HlIoPortOutByte(ptr long) @ stdcall HlIoPortOutByte(ptr long)
@ stdcall RtlCopyMemory(ptr ptr long) @ stdcall RtlCopyMemory(ptr ptr long)
@ stdcall RtlSameMemory(ptr ptr long) @ stdcall RtlSameMemory(ptr ptr long)
@ stdcall RtlWideStringCompare(wstr wstr long) @ stdcall RtlWideStringCompare(wstr wstr long)
@ stdcall RtlWideStringTokenize(wstr wstr wstr)