Skip to content

Commit b2aa694

Browse files
fkgozalimeta-codesync[bot]
authored andcommitted
Fix -Wnullable-to-nonnull-conversion for Xcode 26.4 (#56518)
Summary: Pull Request resolved: #56518 The fix adds null-coalescing fallbacks (`?: ""`) for UTF8String calls that return `const char * _Nullable` but are passed to `std::string` constructors or C++ functions expecting `const char * _Nonnull`. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D101668743 fbshipit-source-id: 80920f25317b0c258387f4b2701b35afe20e3896
1 parent c533369 commit b2aa694

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ - (LinesMeasurements)getLinesForAttributedString:(facebook::react::AttributedStr
209209

210210
CGFloat baseline = [layoutManager locationForGlyphAtIndex:range.location].y;
211211
auto line = LineMeasurement{
212-
std::string([renderedString UTF8String]),
212+
std::string(
213+
[renderedString UTF8String] != nullptr ? [renderedString UTF8String] : ""),
213214
rect,
214215
overallRect.size.height - baseline,
215216
font.capHeight,

packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ @implementation UIView (ColorOverlays)
1111

1212
- (void)setBackgroundColorWithColorString:(NSString *)colorString
1313
{
14-
UIColor *color = [UIView UIColorFromHexString:std::string([colorString UTF8String])];
14+
const char *colorUTF8 = [colorString UTF8String];
15+
UIColor *color = [UIView UIColorFromHexString:std::string(colorUTF8 != nullptr ? colorUTF8 : "")];
1516
self.backgroundColor = color;
1617
}
1718

@@ -23,7 +24,8 @@ - (void)addColorOverlays:(const NSArray *)overlayColors
2324
id colorString = [overlayColors objectAtIndex:i];
2425
CGRect rect = CGRectMake(viewBounds.origin.x + width * i, viewBounds.origin.y, width, viewBounds.size.height);
2526
UIView *overlayView = [[UIView alloc] initWithFrame:rect];
26-
UIColor *color = [UIView UIColorFromHexString:std::string([colorString UTF8String])];
27+
const char *colorUTF8 = [colorString UTF8String];
28+
UIColor *color = [UIView UIColorFromHexString:std::string(colorUTF8 != nullptr ? colorUTF8 : "")];
2729
overlayView.backgroundColor = color;
2830
[self addSubview:overlayView];
2931
}

0 commit comments

Comments
 (0)