Skip to content

Commit de921d3

Browse files
author
Sergey Minakov
committed
[SR-3052] Use UTF-8 string length where UTF-8 encoding is used.
1 parent 44aa0e8 commit de921d3

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

CoreFoundation/AppServices.subproj/CFUserNotification.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringR
198198
if (sessionID) {
199199
char sessionid[MAX_PORT_NAME_LENGTH + 1];
200200
CFIndex len = MAX_PORT_NAME_LENGTH - sizeof(NOTIFICATION_PORT_NAME) - sizeof(NOTIFICATION_PORT_NAME_SUFFIX);
201-
CFStringGetBytes(sessionID, CFRangeMake(0, CFStringGetLength(sessionID)), kCFStringEncodingUTF8, 0, false, (uint8_t *)sessionid, len, &size);
201+
CFStringGetBytes(sessionID, CFRangeMake(0, CFStringGetLengthUTF8(sessionID)), kCFStringEncodingUTF8, 0, false, (uint8_t *)sessionid, len, &size);
202202
sessionid[len - 1] = '\0';
203203
strlcat(namebuffer, NOTIFICATION_PORT_NAME_SUFFIX, sizeof(namebuffer));
204204
strlcat(namebuffer, sessionid, sizeof(namebuffer));

CoreFoundation/Base.subproj/CFPlatform.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ static wchar_t *createWideFileSystemRepresentation(const char *str, CFIndex *res
767767
static void copyToNarrowFileSystemRepresentation(const wchar_t *wide, CFIndex dstBufSize, char *dstbuf) {
768768
// Get the real length of the wide string in UTF8 characters
769769
CFStringRef cfStr = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, (const UniChar *)wide, wcslen(wide));
770-
CFIndex strLen = CFStringGetLength(cfStr);
770+
CFIndex strLen = CFStringGetLengthUTF8(cfStr);
771771
CFIndex bytesUsed;
772772

773773
// Copy the wide string into the buffer and terminate

CoreFoundation/Base.subproj/CFRuntime.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1797,12 +1797,12 @@ const char *_NSPrintForDebugger(void *cf) {
17971797
}
17981798

17991799
CFIndex bufferSize = 0;
1800-
CFIndex numberConverted = CFStringGetBytes((CFStringRef)cf, CFRangeMake(0, CFStringGetLength((CFStringRef)cf)), kCFStringEncodingUTF8, 0, false, NULL, 0, &bufferSize);
1800+
CFIndex numberConverted = CFStringGetBytes((CFStringRef)cf, CFRangeMake(0, CFStringGetLengthUTF8((CFStringRef)cf)), kCFStringEncodingUTF8, 0, false, NULL, 0, &bufferSize);
18011801
const char *result = malloc(bufferSize);
18021802
if (!result) {
18031803
return "<unable to fetch description>";
18041804
}
1805-
CFStringGetBytes((CFStringRef)cf, CFRangeMake(0, CFStringGetLength((CFStringRef)cf)), kCFStringEncodingUTF8, 0, false, (UInt8 *)result, bufferSize, NULL);
1805+
CFStringGetBytes((CFStringRef)cf, CFRangeMake(0, CFStringGetLengthUTF8((CFStringRef)cf)), kCFStringEncodingUTF8, 0, false, (UInt8 *)result, bufferSize, NULL);
18061806
// Yes, this leaks
18071807
return result;
18081808
}

CoreFoundation/Base.subproj/CFUtilities.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ const char *_CFPrintForDebugger(const void *obj) {
496496
}
497497

498498
if (str != NULL) {
499-
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLength(str)), kCFStringEncodingUTF8, 0, FALSE, NULL, 0, &cnt);
499+
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLengthUTF8(str)), kCFStringEncodingUTF8, 0, FALSE, NULL, 0, &cnt);
500500
}
501501
result = (char *) malloc(cnt + 2); // 1 for '\0', 1 for an optional '\n'
502502
if (str != NULL) {
503-
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLength(str)), kCFStringEncodingUTF8, 0, FALSE, (UInt8 *) result, cnt, &cnt);
503+
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLengthUTF8(str)), kCFStringEncodingUTF8, 0, FALSE, (UInt8 *) result, cnt, &cnt);
504504
}
505505
result[cnt] = '\0';
506506

CoreFoundation/Parsing.subproj/CFPropertyList.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ static void parseEntityReference_pl(_CFXMLPlistParseInfo *pInfo, CFMutableDataRe
10741074
}
10751075
uint8_t tmpBuf[6]; // max of 6 bytes for UTF8
10761076
CFIndex tmpBufLength = 0;
1077-
CFStringGetBytes(oneChar, CFRangeMake(0, CFStringGetLength(oneChar)), kCFStringEncodingUTF8, 0, NO, tmpBuf, 6, &tmpBufLength);
1077+
CFStringGetBytes(oneChar, CFRangeMake(0, CFStringGetLengthUTF8(oneChar)), kCFStringEncodingUTF8, 0, NO, tmpBuf, 6, &tmpBufLength);
10781078
CFDataAppendBytes(stringData, tmpBuf, tmpBufLength);
10791079
__CFPListRelease(oneChar, pInfo->allocator);
10801080
return;
@@ -2464,10 +2464,10 @@ static Boolean _CFPropertyListCreateFromUTF8Data(CFAllocatorRef allocator, CFDat
24642464

24652465
static CFDataRef _createUTF8DataFromString(CFAllocatorRef allocator, CFStringRef str) {
24662466
CFIndex bytesNeeded = 0;
2467-
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLength(str)), kCFStringEncodingUTF8, 0, false, NULL, 0, &bytesNeeded);
2467+
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLengthUTF8(str)), kCFStringEncodingUTF8, 0, false, NULL, 0, &bytesNeeded);
24682468

24692469
const char *bytes = (const char *)CFAllocatorAllocate(allocator, bytesNeeded, 0);
2470-
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLength(str)), kCFStringEncodingUTF8, 0, false, (uint8_t *)bytes, bytesNeeded, NULL);
2470+
CFStringGetBytes(str, CFRangeMake(0, CFStringGetLengthUTF8(str)), kCFStringEncodingUTF8, 0, false, (uint8_t *)bytes, bytesNeeded, NULL);
24712471

24722472
CFDataRef utf8Data = CFDataCreateWithBytesNoCopy(allocator, (const UInt8 *)bytes, bytesNeeded, allocator);
24732473
return utf8Data;

CoreFoundation/PlugIn.subproj/CFBundle_Locale.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static CFMutableArrayRef _CFBundleCreateMutableArrayOfFallbackLanguages(CFArrayR
683683
CFIndex usedLength;
684684

685685
// The max size available is -1 because we need to reserve space for the last NULL byte.
686-
CFIndex theLocalizationLength = CFStringGetLength(theLocalization);
686+
CFIndex theLocalizationLength = CFStringGetLengthUTF8(theLocalization);
687687
CFIndex charactersConverted = CFStringGetBytes(theLocalization, CFRangeMake(0, theLocalizationLength), kCFStringEncodingUTF8, 0, false, (UInt8 *)strings, last - strings - 1, &usedLength);
688688
if (charactersConverted == theLocalizationLength) {
689689
stringPointers[i] = strings;

CoreFoundation/RunLoop.subproj/CFMessagePort.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static CFStringRef __CFMessagePortSanitizeStringName(CFStringRef name, uint8_t *
297297
CFIndex utflen;
298298
CFStringRef result = NULL;
299299
utfname = CFAllocatorAllocate(kCFAllocatorSystemDefault, __kCFMessagePortMaxNameLength + 1, 0);
300-
CFStringGetBytes(name, CFRangeMake(0, CFStringGetLength(name)), kCFStringEncodingUTF8, 0, false, utfname, __kCFMessagePortMaxNameLength, &utflen);
300+
CFStringGetBytes(name, CFRangeMake(0, CFStringGetLengthUTF8(name)), kCFStringEncodingUTF8, 0, false, utfname, __kCFMessagePortMaxNameLength, &utflen);
301301
utfname[utflen] = '\0';
302302
if (strlen((const char *)utfname) != utflen) {
303303
/* PCA 9194709: refuse to sanitize a string with an embedded nul character */

CoreFoundation/URL.subproj/CFURL.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ static Boolean _appendPercentEscapesForCharacter(UniChar *ch, Boolean isSurrogat
939939
static CFStringRef UnescapeAllWithUTF8(CFAllocatorRef alloc, CFStringRef originalString) CF_RETURNS_RETAINED
940940
{
941941
CFStringRef result = NULL;
942-
CFIndex strLength = CFStringGetLength(originalString);
942+
CFIndex strLength = CFStringGetLengthUTF8(originalString);
943943
CFIndex maxBufferSize = CFStringGetMaximumSizeForEncoding(strLength, kCFStringEncodingUTF8);
944944
CFIndex stackBufferSize = 2096;
945945
STACK_BUFFER_DECL(UInt8, escapedStackBuf, stackBufferSize *2);
@@ -4152,7 +4152,7 @@ static Boolean CanonicalFileURLStringToFileSystemRepresentation(CFStringRef str,
41524152
if ( inBuffer && inBufferLen ) {
41534153
STACK_BUFFER_DECL(UInt8, stackEscapedBuf, PATH_MAX * 3); // worst case size is every unicode code point could be a 3-byte UTF8 sequence
41544154
UInt8 *escapedBuf;
4155-
CFIndex strLength = CFStringGetLength(str) - (fileURLPrefixLength - 1);
4155+
CFIndex strLength = CFStringGetLengthUTF8(str) - (fileURLPrefixLength - 1);
41564156
if ( strLength != 0 ) {
41574157
CFIndex maxBufLength = strLength * 3;
41584158
CFIndex usedBufLen;

0 commit comments

Comments
 (0)