Skip to content

Commit 35fda0b

Browse files
committed
Improve maro usage
1 parent 006055c commit 35fda0b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

phlib/basesup.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ PSTR PhDuplicateBytesZ(
651651
PSTR newString;
652652
SIZE_T length;
653653

654-
length = strlen(String) + 1; // include the null terminator
654+
length = strlen(String) + sizeof(ANSI_NULL); // include the null terminator
655655

656656
newString = PhAllocate(length);
657657
memcpy(newString, String, length);
@@ -674,7 +674,7 @@ PSTR PhDuplicateBytesZSafe(
674674
PSTR newString;
675675
SIZE_T length;
676676

677-
length = strlen(String) + 1; // include the null terminator
677+
length = strlen(String) + sizeof(ANSI_NULL); // include the null terminator
678678

679679
newString = PhAllocateSafe(length);
680680

@@ -700,7 +700,7 @@ PWSTR PhDuplicateStringZ(
700700
PWSTR newString;
701701
SIZE_T length;
702702

703-
length = (PhCountStringZ(String) + 1) * sizeof(WCHAR); // include the null terminator
703+
length = (PhCountStringZ(String) + sizeof(UNICODE_NULL)) * sizeof(WCHAR); // include the null terminator
704704

705705
newString = PhAllocate(length);
706706
memcpy(newString, String, length);
@@ -753,10 +753,10 @@ BOOLEAN PhCopyBytesZ(
753753

754754
// Copy the string if there is enough room.
755755

756-
if (OutputBuffer && OutputCount >= i + 1) // need one character for null terminator
756+
if (OutputBuffer && OutputCount >= i + sizeof(ANSI_NULL)) // need one character for null terminator
757757
{
758758
memcpy(OutputBuffer, InputBuffer, i);
759-
OutputBuffer[i] = 0;
759+
OutputBuffer[i] = ANSI_NULL;
760760
copied = TRUE;
761761
}
762762
else
@@ -765,7 +765,7 @@ BOOLEAN PhCopyBytesZ(
765765
}
766766

767767
if (ReturnCount)
768-
*ReturnCount = i + 1;
768+
*ReturnCount = i + sizeof(ANSI_NULL);
769769

770770
return copied;
771771
}
@@ -815,10 +815,10 @@ BOOLEAN PhCopyStringZ(
815815

816816
// Copy the string if there is enough room.
817817

818-
if (OutputBuffer && OutputCount >= i + 1) // need one character for null terminator
818+
if (OutputBuffer && OutputCount >= i + sizeof(UNICODE_NULL)) // need one character for null terminator
819819
{
820820
memcpy(OutputBuffer, InputBuffer, i * sizeof(WCHAR));
821-
OutputBuffer[i] = 0;
821+
OutputBuffer[i] = UNICODE_NULL;
822822
copied = TRUE;
823823
}
824824
else
@@ -827,7 +827,7 @@ BOOLEAN PhCopyStringZ(
827827
}
828828

829829
if (ReturnCount)
830-
*ReturnCount = i + 1;
830+
*ReturnCount = i + sizeof(UNICODE_NULL);
831831

832832
return copied;
833833
}
@@ -877,10 +877,10 @@ BOOLEAN PhCopyStringZFromBytes(
877877

878878
// Copy the string if there is enough room.
879879

880-
if (OutputBuffer && OutputCount >= i + 1) // need one character for null terminator
880+
if (OutputBuffer && OutputCount >= i + sizeof(UNICODE_NULL)) // need one character for null terminator
881881
{
882882
PhZeroExtendToUtf16Buffer(InputBuffer, i, OutputBuffer);
883-
OutputBuffer[i] = 0;
883+
OutputBuffer[i] = UNICODE_NULL;
884884
copied = TRUE;
885885
}
886886
else
@@ -889,7 +889,7 @@ BOOLEAN PhCopyStringZFromBytes(
889889
}
890890

891891
if (ReturnCount)
892-
*ReturnCount = i + 1;
892+
*ReturnCount = i + sizeof(UNICODE_NULL);
893893

894894
return copied;
895895
}
@@ -957,7 +957,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
957957

958958
// Convert the string to Unicode if there is enough room.
959959

960-
if (OutputBuffer && OutputCount >= unicodeBytes / sizeof(WCHAR) + 1)
960+
if (OutputBuffer && OutputCount >= unicodeBytes / sizeof(WCHAR) + sizeof(UNICODE_NULL))
961961
{
962962
status = RtlMultiByteToUnicodeN(
963963
OutputBuffer,
@@ -984,7 +984,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
984984
}
985985

986986
if (ReturnCount)
987-
*ReturnCount = unicodeBytes / sizeof(WCHAR) + 1;
987+
*ReturnCount = unicodeBytes / sizeof(WCHAR) + sizeof(UNICODE_NULL);
988988

989989
return copied;
990990
}
@@ -2187,7 +2187,7 @@ PPH_STRING PhCreateStringEx(
21872187
PPH_STRING string;
21882188

21892189
string = PhCreateObject(
2190-
FIELD_OFFSET(PH_STRING, Data) + Length + sizeof(WCHAR), // Null terminator
2190+
UFIELD_OFFSET(PH_STRING, Data) + Length + sizeof(UNICODE_NULL), // Null terminator for compatibility
21912191
PhStringType
21922192
);
21932193

@@ -2483,7 +2483,7 @@ PPH_BYTES PhCreateBytesEx(
24832483
PPH_BYTES bytes;
24842484

24852485
bytes = PhCreateObject(
2486-
FIELD_OFFSET(PH_BYTES, Data) + Length + sizeof(CHAR), // Null terminator for compatibility
2486+
UFIELD_OFFSET(PH_BYTES, Data) + Length + sizeof(ANSI_NULL), // Null terminator for compatibility
24872487
PhBytesType
24882488
);
24892489

@@ -3513,7 +3513,7 @@ VOID PhpResizeStringBuilder(
35133513
memcpy(
35143514
newString->Buffer,
35153515
StringBuilder->String->Buffer,
3516-
StringBuilder->String->Length + sizeof(WCHAR) // Include null terminator
3516+
StringBuilder->String->Length + sizeof(UNICODE_NULL) // Include null terminator
35173517
);
35183518

35193519
// Copy the old string length.
@@ -3889,7 +3889,7 @@ VOID PhpResizeBytesBuilder(
38893889
memcpy(
38903890
newBytes->Buffer,
38913891
BytesBuilder->Bytes->Buffer,
3892-
BytesBuilder->Bytes->Length + sizeof(CHAR) // Include null terminator
3892+
BytesBuilder->Bytes->Length + sizeof(ANSI_NULL) // Include null terminator
38933893
);
38943894

38953895
// Copy the old byte string length.
@@ -5217,7 +5217,7 @@ PVOID PhAllocateFromFreeList(
52175217
}
52185218
else
52195219
{
5220-
entry = PhAllocate(FIELD_OFFSET(PH_FREE_LIST_ENTRY, Body) + FreeList->Size);
5220+
entry = PhAllocate(UFIELD_OFFSET(PH_FREE_LIST_ENTRY, Body) + FreeList->Size);
52215221
}
52225222

52235223
return &entry->Body;

0 commit comments

Comments
 (0)