@@ -651,7 +651,7 @@ PSTR PhDuplicateBytesZ(
651
651
PSTR newString ;
652
652
SIZE_T length ;
653
653
654
- length = strlen (String ) + 1 ; // include the null terminator
654
+ length = strlen (String ) + sizeof ( ANSI_NULL ) ; // include the null terminator
655
655
656
656
newString = PhAllocate (length );
657
657
memcpy (newString , String , length );
@@ -674,7 +674,7 @@ PSTR PhDuplicateBytesZSafe(
674
674
PSTR newString ;
675
675
SIZE_T length ;
676
676
677
- length = strlen (String ) + 1 ; // include the null terminator
677
+ length = strlen (String ) + sizeof ( ANSI_NULL ) ; // include the null terminator
678
678
679
679
newString = PhAllocateSafe (length );
680
680
@@ -700,7 +700,7 @@ PWSTR PhDuplicateStringZ(
700
700
PWSTR newString ;
701
701
SIZE_T length ;
702
702
703
- length = (PhCountStringZ (String ) + 1 ) * sizeof (WCHAR ); // include the null terminator
703
+ length = (PhCountStringZ (String ) + sizeof ( UNICODE_NULL ) ) * sizeof (WCHAR ); // include the null terminator
704
704
705
705
newString = PhAllocate (length );
706
706
memcpy (newString , String , length );
@@ -753,10 +753,10 @@ BOOLEAN PhCopyBytesZ(
753
753
754
754
// Copy the string if there is enough room.
755
755
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
757
757
{
758
758
memcpy (OutputBuffer , InputBuffer , i );
759
- OutputBuffer [i ] = 0 ;
759
+ OutputBuffer [i ] = ANSI_NULL ;
760
760
copied = TRUE;
761
761
}
762
762
else
@@ -765,7 +765,7 @@ BOOLEAN PhCopyBytesZ(
765
765
}
766
766
767
767
if (ReturnCount )
768
- * ReturnCount = i + 1 ;
768
+ * ReturnCount = i + sizeof ( ANSI_NULL ) ;
769
769
770
770
return copied ;
771
771
}
@@ -815,10 +815,10 @@ BOOLEAN PhCopyStringZ(
815
815
816
816
// Copy the string if there is enough room.
817
817
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
819
819
{
820
820
memcpy (OutputBuffer , InputBuffer , i * sizeof (WCHAR ));
821
- OutputBuffer [i ] = 0 ;
821
+ OutputBuffer [i ] = UNICODE_NULL ;
822
822
copied = TRUE;
823
823
}
824
824
else
@@ -827,7 +827,7 @@ BOOLEAN PhCopyStringZ(
827
827
}
828
828
829
829
if (ReturnCount )
830
- * ReturnCount = i + 1 ;
830
+ * ReturnCount = i + sizeof ( UNICODE_NULL ) ;
831
831
832
832
return copied ;
833
833
}
@@ -877,10 +877,10 @@ BOOLEAN PhCopyStringZFromBytes(
877
877
878
878
// Copy the string if there is enough room.
879
879
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
881
881
{
882
882
PhZeroExtendToUtf16Buffer (InputBuffer , i , OutputBuffer );
883
- OutputBuffer [i ] = 0 ;
883
+ OutputBuffer [i ] = UNICODE_NULL ;
884
884
copied = TRUE;
885
885
}
886
886
else
@@ -889,7 +889,7 @@ BOOLEAN PhCopyStringZFromBytes(
889
889
}
890
890
891
891
if (ReturnCount )
892
- * ReturnCount = i + 1 ;
892
+ * ReturnCount = i + sizeof ( UNICODE_NULL ) ;
893
893
894
894
return copied ;
895
895
}
@@ -957,7 +957,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
957
957
958
958
// Convert the string to Unicode if there is enough room.
959
959
960
- if (OutputBuffer && OutputCount >= unicodeBytes / sizeof (WCHAR ) + 1 )
960
+ if (OutputBuffer && OutputCount >= unicodeBytes / sizeof (WCHAR ) + sizeof ( UNICODE_NULL ) )
961
961
{
962
962
status = RtlMultiByteToUnicodeN (
963
963
OutputBuffer ,
@@ -984,7 +984,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
984
984
}
985
985
986
986
if (ReturnCount )
987
- * ReturnCount = unicodeBytes / sizeof (WCHAR ) + 1 ;
987
+ * ReturnCount = unicodeBytes / sizeof (WCHAR ) + sizeof ( UNICODE_NULL ) ;
988
988
989
989
return copied ;
990
990
}
@@ -2187,7 +2187,7 @@ PPH_STRING PhCreateStringEx(
2187
2187
PPH_STRING string ;
2188
2188
2189
2189
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
2191
2191
PhStringType
2192
2192
);
2193
2193
@@ -2483,7 +2483,7 @@ PPH_BYTES PhCreateBytesEx(
2483
2483
PPH_BYTES bytes ;
2484
2484
2485
2485
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
2487
2487
PhBytesType
2488
2488
);
2489
2489
@@ -3513,7 +3513,7 @@ VOID PhpResizeStringBuilder(
3513
3513
memcpy (
3514
3514
newString -> Buffer ,
3515
3515
StringBuilder -> String -> Buffer ,
3516
- StringBuilder -> String -> Length + sizeof (WCHAR ) // Include null terminator
3516
+ StringBuilder -> String -> Length + sizeof (UNICODE_NULL ) // Include null terminator
3517
3517
);
3518
3518
3519
3519
// Copy the old string length.
@@ -3889,7 +3889,7 @@ VOID PhpResizeBytesBuilder(
3889
3889
memcpy (
3890
3890
newBytes -> Buffer ,
3891
3891
BytesBuilder -> Bytes -> Buffer ,
3892
- BytesBuilder -> Bytes -> Length + sizeof (CHAR ) // Include null terminator
3892
+ BytesBuilder -> Bytes -> Length + sizeof (ANSI_NULL ) // Include null terminator
3893
3893
);
3894
3894
3895
3895
// Copy the old byte string length.
@@ -5217,7 +5217,7 @@ PVOID PhAllocateFromFreeList(
5217
5217
}
5218
5218
else
5219
5219
{
5220
- entry = PhAllocate (FIELD_OFFSET (PH_FREE_LIST_ENTRY , Body ) + FreeList -> Size );
5220
+ entry = PhAllocate (UFIELD_OFFSET (PH_FREE_LIST_ENTRY , Body ) + FreeList -> Size );
5221
5221
}
5222
5222
5223
5223
return & entry -> Body ;
0 commit comments