Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Fix 'google-readability-braces-around-statements' analyzer warning in macOS and iOS #29723

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions flow/display_list_canvas_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1287,14 +1287,18 @@ class CanvasCompareTester {
const uint32_t* test_row = test_pixels.addr32(0, y);
for (int x = 0; x < width; x++) {
if (bounds && test_row[x] != untouched) {
if (minX > x)
if (minX > x) {
minX = x;
if (minY > y)
}
if (minY > y) {
minY = y;
if (maxX <= x)
}
if (maxX <= x) {
maxX = x + 1;
if (maxY <= y)
}
if (maxY <= y) {
maxY = y + 1;
}
if (!i_bounds.contains(x, y)) {
pixels_oob++;
}
Expand Down
3 changes: 2 additions & 1 deletion flow/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,9 @@ static sk_sp<DisplayList> Build(size_t g_index, size_t v_index) {
for (size_t i = 0; i < allGroups.size(); i++) {
DisplayListInvocationGroup& group = allGroups[i];
size_t j = (i == g_index ? v_index : 0);
if (j >= group.variants.size())
if (j >= group.variants.size()) {
continue;
}
DisplayListInvocation& invocation = group.variants[j];
op_count += invocation.op_count();
byte_count += invocation.raw_byte_count();
Expand Down
3 changes: 2 additions & 1 deletion fml/platform/darwin/string_range_sanitization.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ NSRange RangeForCharacterAtIndex(NSString* text, NSUInteger index) {
if (text == nil || index > text.length) {
return NSMakeRange(NSNotFound, 0);
}
if (index < text.length)
if (index < text.length) {
return [text rangeOfComposedCharacterSequenceAtIndex:index];
}
return NSMakeRange(index, 0);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/ui/window/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ void Window::DispatchPointerDataPacket(const PointerDataPacket& packet) {
void Window::DispatchKeyDataPacket(const KeyDataPacket& packet,
uint64_t response_id) {
std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock();
if (!dart_state)
if (!dart_state) {
return;
}
tonic::DartState::Scope scope(dart_state);

const std::vector<uint8_t>& buffer = packet.data();
Expand Down
6 changes: 4 additions & 2 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ const uint8_t* DartSnapshot::GetInstructionsMapping() const {
}

bool DartSnapshot::IsDontNeedSafe() const {
if (data_ && !data_->IsDontNeedSafe())
if (data_ && !data_->IsDontNeedSafe()) {
return false;
if (instructions_ && !instructions_->IsDontNeedSafe())
}
if (instructions_ && !instructions_->IsDontNeedSafe()) {
return false;
}
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ void PlatformView::UpdateSemantics(SemanticsNodeUpdates update,

void PlatformView::HandlePlatformMessage(
std::unique_ptr<PlatformMessage> message) {
if (auto response = message->response())
if (auto response = message->response()) {
response->CompleteEmpty();
}
}

void PlatformView::OnPreEngineRestart() const {}
Expand Down
3 changes: 2 additions & 1 deletion shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
snapshot_surface = surface_.get();
} else if (snapshot_surface_producer_) {
pbuffer_surface = snapshot_surface_producer_->CreateSnapshotSurface();
if (pbuffer_surface && pbuffer_surface->GetContext())
if (pbuffer_surface && pbuffer_surface->GetContext()) {
snapshot_surface = pbuffer_surface.get();
}
}

if (!snapshot_surface) {
Expand Down
9 changes: 6 additions & 3 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,15 +1212,18 @@ void Shell::HandleEngineSkiaMessage(std::unique_ptr<PlatformMessage> message) {
rapidjson::Document document;
document.Parse(reinterpret_cast<const char*>(data.GetMapping()),
data.GetSize());
if (document.HasParseError() || !document.IsObject())
if (document.HasParseError() || !document.IsObject()) {
return;
}
auto root = document.GetObject();
auto method = root.FindMember("method");
if (method->value != "Skia.setResourceCacheMaxBytes")
if (method->value != "Skia.setResourceCacheMaxBytes") {
return;
}
auto args = root.FindMember("args");
if (args == root.MemberEnd() || !args->value.IsInt())
if (args == root.MemberEnd() || !args->value.IsInt()) {
return;
}

task_runners_.GetRasterTaskRunner()->PostTask(
[rasterizer = rasterizer_->GetWeakPtr(), max_bytes = args->value.GetInt(),
Expand Down
3 changes: 2 additions & 1 deletion shell/common/vsync_waiter_fallback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ static fml::TimePoint SnapToNextTick(fml::TimePoint value,
fml::TimePoint tick_phase,
fml::TimeDelta tick_interval) {
fml::TimeDelta offset = (tick_phase - value) % tick_interval;
if (offset != fml::TimeDelta::Zero())
if (offset != fml::TimeDelta::Zero()) {
offset = offset + tick_interval;
}
return value + offset;
}

Expand Down
42 changes: 26 additions & 16 deletions shell/platform/darwin/common/framework/Source/FlutterChannels.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ - (void)sendMessage:(id)message {

- (void)sendMessage:(id)message reply:(FlutterReply)callback {
FlutterBinaryReply reply = ^(NSData* data) {
if (callback)
if (callback) {
callback([_codec decode:data]);
}
};
[_messenger sendOnChannel:_name message:[_codec encode:message] binaryReply:reply];
}
Expand Down Expand Up @@ -118,10 +119,12 @@ - (void)dealloc {
}

- (BOOL)isEqual:(id)object {
if (self == object)
if (self == object) {
return YES;
if (![object isKindOfClass:[FlutterError class]])
}
if (![object isKindOfClass:[FlutterError class]]) {
return NO;
}
FlutterError* other = (FlutterError*)object;
return [self.code isEqual:other.code] &&
((!self.message && !other.message) || [self.message isEqual:other.message]) &&
Expand Down Expand Up @@ -154,10 +157,12 @@ - (void)dealloc {
}

- (BOOL)isEqual:(id)object {
if (self == object)
if (self == object) {
return YES;
if (![object isKindOfClass:[FlutterMethodCall class]])
}
if (![object isKindOfClass:[FlutterMethodCall class]]) {
return NO;
}
FlutterMethodCall* other = (FlutterMethodCall*)object;
return [self.method isEqual:[other method]] &&
((!self.arguments && !other.arguments) || [self.arguments isEqual:other.arguments]);
Expand Down Expand Up @@ -242,12 +247,13 @@ - (void)setMethodCallHandler:(FlutterMethodCallHandler)handler {
FlutterBinaryMessageHandler messageHandler = ^(NSData* message, FlutterBinaryReply callback) {
FlutterMethodCall* call = [codec decodeMethodCall:message];
handler(call, ^(id result) {
if (result == FlutterMethodNotImplemented)
if (result == FlutterMethodNotImplemented) {
callback(nil);
else if ([result isKindOfClass:[FlutterError class]])
} else if ([result isKindOfClass:[FlutterError class]]) {
callback([codec encodeErrorEnvelope:(FlutterError*)result]);
else
} else {
callback([codec encodeSuccessEnvelope:result]);
}
});
};
_connection = [_messenger setMessageHandlerOnChannel:_name binaryMessageHandler:messageHandler];
Expand Down Expand Up @@ -309,23 +315,26 @@ static void SetStreamHandlerMessageHandlerOnChannel(NSObject<FlutterStreamHandle
if ([call.method isEqual:@"listen"]) {
if (currentSink) {
FlutterError* error = [handler onCancelWithArguments:nil];
if (error)
if (error) {
NSLog(@"Failed to cancel existing stream: %@. %@ (%@)", error.code, error.message,
error.details);
}
}
currentSink = ^(id event) {
if (event == FlutterEndOfEventStream)
if (event == FlutterEndOfEventStream) {
[messenger sendOnChannel:name message:nil];
else if ([event isKindOfClass:[FlutterError class]])
} else if ([event isKindOfClass:[FlutterError class]]) {
[messenger sendOnChannel:name message:[codec encodeErrorEnvelope:(FlutterError*)event]];
else
} else {
[messenger sendOnChannel:name message:[codec encodeSuccessEnvelope:event]];
}
};
FlutterError* error = [handler onListenWithArguments:call.arguments eventSink:currentSink];
if (error)
if (error) {
callback([codec encodeErrorEnvelope:error]);
else
} else {
callback([codec encodeSuccessEnvelope:nil]);
}
} else if ([call.method isEqual:@"cancel"]) {
if (!currentSink) {
callback(
Expand All @@ -336,10 +345,11 @@ static void SetStreamHandlerMessageHandlerOnChannel(NSObject<FlutterStreamHandle
}
currentSink = nil;
FlutterError* error = [handler onCancelWithArguments:call.arguments];
if (error)
if (error) {
callback([codec encodeErrorEnvelope:error]);
else
} else {
callback([codec encodeSuccessEnvelope:nil]);
}
} else {
callback(nil);
}
Expand Down
15 changes: 10 additions & 5 deletions shell/platform/darwin/common/framework/Source/FlutterCodecs.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ + (instancetype)sharedInstance {
}

- (NSData*)encode:(id)message {
if (message == nil)
if (message == nil) {
return nil;
}
NSAssert([message isKindOfClass:[NSString class]], @"");
NSString* stringMessage = message;
const char* utf8 = stringMessage.UTF8String;
return [NSData dataWithBytes:utf8 length:strlen(utf8)];
}

- (NSString*)decode:(NSData*)message {
if (message == nil)
if (message == nil) {
return nil;
}
return [[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding] autorelease];
}
@end
Expand All @@ -60,8 +62,9 @@ + (instancetype)sharedInstance {
}

- (NSData*)encode:(id)message {
if (message == nil)
if (message == nil) {
return nil;
}
NSData* encoding;
if ([message isKindOfClass:[NSArray class]] || [message isKindOfClass:[NSDictionary class]]) {
encoding = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
Expand All @@ -78,8 +81,9 @@ - (NSData*)encode:(id)message {
}

- (id)decode:(NSData*)message {
if ([message length] == 0)
if ([message length] == 0) {
return nil;
}
BOOL isSimpleValue = NO;
id decoded = nil;
if (0 < message.length) {
Expand Down Expand Up @@ -143,8 +147,9 @@ - (FlutterMethodCall*)decodeMethodCall:(NSData*)message {

- (id)decodeEnvelope:(NSData*)envelope {
NSArray* array = [[FlutterJSONMessageCodec sharedInstance] decode:envelope];
if (array.count == 1)
if (array.count == 1) {
return [self unwrapNil:array[0]];
}
NSAssert(array.count == 3, @"Invalid JSON envelope");
id code = array[0];
id message = [self unwrapNil:array[1]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ - (void)dealloc {
}

- (NSData*)encode:(id)message {
if (message == nil)
if (message == nil) {
return nil;
}
NSMutableData* data = [NSMutableData dataWithCapacity:32];
FlutterStandardWriter* writer = [_readerWriter writerWithData:data];
[writer writeValue:message];
return data;
}

- (id)decode:(NSData*)message {
if ([message length] == 0)
if ([message length] == 0) {
return nil;
}
FlutterStandardReader* reader = [_readerWriter readerWithData:message];
id value = [reader readValue];
NSAssert(![reader hasMore], @"Corrupted standard message");
Expand Down Expand Up @@ -193,10 +195,12 @@ - (void)dealloc {
}

- (BOOL)isEqual:(id)object {
if (self == object)
if (self == object) {
return YES;
if (![object isKindOfClass:[FlutterStandardTypedData class]])
}
if (![object isKindOfClass:[FlutterStandardTypedData class]]) {
return NO;
}
FlutterStandardTypedData* other = (FlutterStandardTypedData*)object;
return self.type == other.type && self.elementCount == other.elementCount &&
[self.data isEqual:other.data];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@
void checkEncodeDecode(id value, NSData* expectedEncoding) {
FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance];
NSData* encoded = [codec encode:value];
if (expectedEncoding == nil)
if (expectedEncoding == nil) {
ASSERT_TRUE(encoded == nil);
else
} else {
ASSERT_TRUE([encoded isEqual:expectedEncoding]);
}
id decoded = [codec decode:encoded];
if (value == nil || value == [NSNull null])
if (value == nil || value == [NSNull null]) {
ASSERT_TRUE(decoded == nil);
else
} else {
ASSERT_TRUE([value isEqual:decoded]);
}
}

void checkEncodeDecode(id value) {
FlutterStandardMessageCodec* codec = [FlutterStandardMessageCodec sharedInstance];
NSData* encoded = [codec encode:value];
id decoded = [codec decode:encoded];
if (value == nil || value == [NSNull null])
if (value == nil || value == [NSNull null]) {
ASSERT_TRUE(decoded == nil);
else
} else {
ASSERT_TRUE([value isEqual:decoded]);
}
}

TEST(FlutterStandardCodec, CanDecodeZeroLength) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,21 @@ - (void)setSystemChromePreferredOrientations:(NSArray*)orientations {
mask |= UIInterfaceOrientationMaskAll;
} else {
for (NSString* orientation in orientations) {
if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"])
if ([orientation isEqualToString:@"DeviceOrientation.portraitUp"]) {
mask |= UIInterfaceOrientationMaskPortrait;
else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"])
} else if ([orientation isEqualToString:@"DeviceOrientation.portraitDown"]) {
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"])
} else if ([orientation isEqualToString:@"DeviceOrientation.landscapeLeft"]) {
mask |= UIInterfaceOrientationMaskLandscapeLeft;
else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"])
} else if ([orientation isEqualToString:@"DeviceOrientation.landscapeRight"]) {
mask |= UIInterfaceOrientationMaskLandscapeRight;
}
}
}

if (!mask)
if (!mask) {
return;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:@(kOrientationUpdateNotificationName)
object:nil
Expand Down Expand Up @@ -205,8 +207,9 @@ - (void)restoreSystemChromeSystemUIOverlays {

- (void)setSystemChromeSystemUIOverlayStyle:(NSDictionary*)message {
NSString* brightness = message[@"statusBarBrightness"];
if (brightness == (id)[NSNull null])
if (brightness == (id)[NSNull null]) {
return;
}

UIStatusBarStyle statusBarStyle;
if ([brightness isEqualToString:@"Brightness.dark"]) {
Expand Down
Loading