Skip to content

Commit facf571

Browse files
pi1024eparkera
authored andcommitted
This function is not clear in that the else branch ALWAYS following the rest of the method due to early returns. Because the two top branches always return, I removed the else statement, and put encoding & 0xFFF in the switch statement itself instead of modifying the encoding directly. (#2550)
1 parent 5bb9828 commit facf571

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

CoreFoundation/String.subproj/CFString.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,12 @@ CFStringEncoding CFStringFileSystemEncoding(void) {
459459
CFIndex CFStringGetMaximumSizeForEncoding(CFIndex length, CFStringEncoding encoding) {
460460
if (encoding == kCFStringEncodingUTF8) {
461461
return (length > (LONG_MAX / 3)) ? kCFNotFound : (length * 3);
462-
} else if ((encoding == kCFStringEncodingUTF32) || (encoding == kCFStringEncodingUTF32BE) || (encoding == kCFStringEncodingUTF32LE)) { // UTF-32
462+
}
463+
if ((encoding == kCFStringEncodingUTF32) || (encoding == kCFStringEncodingUTF32BE) || (encoding == kCFStringEncodingUTF32LE)) { // UTF-32
463464
return (length > (LONG_MAX / sizeof(UTF32Char))) ? kCFNotFound : (length * sizeof(UTF32Char));
464-
} else {
465-
encoding &= 0xFFF; // Mask off non-base part
466465
}
467-
switch (encoding) {
466+
467+
switch (encoding & 0xFFF) { // Mask off non-base part
468468
case kCFStringEncodingUnicode:
469469
return (length > (LONG_MAX / sizeof(UniChar))) ? kCFNotFound : (length * sizeof(UniChar));
470470

@@ -476,8 +476,6 @@ CFIndex CFStringGetMaximumSizeForEncoding(CFIndex length, CFStringEncoding encod
476476
case kCFStringEncodingISOLatin1:
477477
case kCFStringEncodingNextStepLatin:
478478
case kCFStringEncodingASCII:
479-
return length / sizeof(uint8_t);
480-
481479
default:
482480
return length / sizeof(uint8_t);
483481
}

0 commit comments

Comments
 (0)