Skip to content

Commit fd17e08

Browse files
authored
Fix linter errors in mock_engine (flutter#21102)
Make a single-param ctor explicit in order to prevent surprising implicit conversions. Add a check for zero message-size and don't malloc/memcpy the incoming message in those cases. Add braces where they were missing.
1 parent 223bf45 commit fd17e08

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

shell/platform/linux/testing/mock_engine.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct _FlutterPlatformMessageResponseHandle {
3232
bool released;
3333

3434
// Constructor for a response handle generated by the engine.
35-
_FlutterPlatformMessageResponseHandle(std::string channel)
35+
explicit _FlutterPlatformMessageResponseHandle(std::string channel)
3636
: data_callback(nullptr),
3737
user_data(nullptr),
3838
channel(channel),
@@ -61,8 +61,12 @@ struct _FlutterTaskRunner {
6161
channel(channel),
6262
response_handle(response_handle),
6363
message_size(message_size) {
64-
this->message = static_cast<uint8_t*>(malloc(message_size));
65-
memcpy(this->message, message, message_size);
64+
if (message_size > 0) {
65+
this->message = static_cast<uint8_t*>(malloc(message_size));
66+
memcpy(this->message, message, message_size);
67+
} else {
68+
this->message = nullptr;
69+
}
6670
}
6771
~_FlutterTaskRunner() {
6872
if (response_handle != nullptr) {
@@ -80,8 +84,9 @@ static void send_response(
8084
const FlutterPlatformMessageResponseHandle* response_handle,
8185
const uint8_t* message,
8286
size_t message_size) {
83-
if (response_handle == nullptr)
87+
if (response_handle == nullptr) {
8488
return;
89+
}
8590

8691
FlutterTask task;
8792
task.runner = new _FlutterTaskRunner(1234, channel, response_handle, message,
@@ -146,8 +151,9 @@ FlutterEngineResult FlutterEngineRun(size_t version,
146151

147152
FlutterEngineResult result =
148153
FlutterEngineInitialize(version, config, args, user_data, engine_out);
149-
if (result != kSuccess)
154+
if (result != kSuccess) {
150155
return result;
156+
}
151157
return FlutterEngineRunInitialized(*engine_out);
152158
}
153159

@@ -254,8 +260,9 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
254260
? fl_value_get_string(message_value)
255261
: nullptr;
256262
}
257-
if (fl_value_get_length(args) >= 3)
263+
if (fl_value_get_length(args) >= 3) {
258264
details = fl_value_get_list_value(args, 2);
265+
}
259266
response = fl_method_codec_encode_error_envelope(
260267
FL_METHOD_CODEC(codec), code, message, details, &error);
261268
EXPECT_EQ(error, nullptr);
@@ -336,8 +343,9 @@ FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
336343
EXPECT_TRUE(engine->running);
337344

338345
// Send a message so the shell can check the responses received.
339-
if (handle->channel != "test/responses")
346+
if (handle->channel != "test/responses") {
340347
send_message(engine, "test/responses", data, data_length);
348+
}
341349

342350
EXPECT_FALSE(handle->released);
343351

0 commit comments

Comments
 (0)