Fix linter errors in mock_engine (flutter/engine#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.
This commit is contained in:
@@ -32,7 +32,7 @@ struct _FlutterPlatformMessageResponseHandle {
|
||||
bool released;
|
||||
|
||||
// Constructor for a response handle generated by the engine.
|
||||
_FlutterPlatformMessageResponseHandle(std::string channel)
|
||||
explicit _FlutterPlatformMessageResponseHandle(std::string channel)
|
||||
: data_callback(nullptr),
|
||||
user_data(nullptr),
|
||||
channel(channel),
|
||||
@@ -61,8 +61,12 @@ struct _FlutterTaskRunner {
|
||||
channel(channel),
|
||||
response_handle(response_handle),
|
||||
message_size(message_size) {
|
||||
this->message = static_cast<uint8_t*>(malloc(message_size));
|
||||
memcpy(this->message, message, message_size);
|
||||
if (message_size > 0) {
|
||||
this->message = static_cast<uint8_t*>(malloc(message_size));
|
||||
memcpy(this->message, message, message_size);
|
||||
} else {
|
||||
this->message = nullptr;
|
||||
}
|
||||
}
|
||||
~_FlutterTaskRunner() {
|
||||
if (response_handle != nullptr) {
|
||||
@@ -80,8 +84,9 @@ static void send_response(
|
||||
const FlutterPlatformMessageResponseHandle* response_handle,
|
||||
const uint8_t* message,
|
||||
size_t message_size) {
|
||||
if (response_handle == nullptr)
|
||||
if (response_handle == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
FlutterTask task;
|
||||
task.runner = new _FlutterTaskRunner(1234, channel, response_handle, message,
|
||||
@@ -146,8 +151,9 @@ FlutterEngineResult FlutterEngineRun(size_t version,
|
||||
|
||||
FlutterEngineResult result =
|
||||
FlutterEngineInitialize(version, config, args, user_data, engine_out);
|
||||
if (result != kSuccess)
|
||||
if (result != kSuccess) {
|
||||
return result;
|
||||
}
|
||||
return FlutterEngineRunInitialized(*engine_out);
|
||||
}
|
||||
|
||||
@@ -254,8 +260,9 @@ FlutterEngineResult FlutterEngineSendPlatformMessage(
|
||||
? fl_value_get_string(message_value)
|
||||
: nullptr;
|
||||
}
|
||||
if (fl_value_get_length(args) >= 3)
|
||||
if (fl_value_get_length(args) >= 3) {
|
||||
details = fl_value_get_list_value(args, 2);
|
||||
}
|
||||
response = fl_method_codec_encode_error_envelope(
|
||||
FL_METHOD_CODEC(codec), code, message, details, &error);
|
||||
EXPECT_EQ(error, nullptr);
|
||||
@@ -336,8 +343,9 @@ FlutterEngineResult FlutterEngineSendPlatformMessageResponse(
|
||||
EXPECT_TRUE(engine->running);
|
||||
|
||||
// Send a message so the shell can check the responses received.
|
||||
if (handle->channel != "test/responses")
|
||||
if (handle->channel != "test/responses") {
|
||||
send_message(engine, "test/responses", data, data_length);
|
||||
}
|
||||
|
||||
EXPECT_FALSE(handle->released);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user