Skip to content

Commit a4a1881

Browse files
committed
fix some more warnings
1 parent 0f59af4 commit a4a1881

File tree

9 files changed

+157
-93
lines changed

9 files changed

+157
-93
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ target_include_directories(flutterpi_module PUBLIC
168168
)
169169

170170
target_compile_options(flutterpi_module PUBLIC
171-
$<$<CONFIG:Debug>:-O0 -Wall -Wextra -Wno-sign-compare -Wswitch-enum -Wformat -Wdouble-promotion -Werror -ggdb -U_FORTIFY_SOURCE -DDEBUG>
171+
$<$<CONFIG:Debug>:-O0 -Wall -Wextra -Wno-sign-compare -Wswitch-enum -Wformat -Wformat-pedantic -Wdouble-promotion -Werror -ggdb -U_FORTIFY_SOURCE -DDEBUG>
172172
$<$<CONFIG:RelWithDebInfo>:-O3 -Wall -Wextra -Wno-sign-compare -ggdb -DNDEBUG>
173173
$<$<CONFIG:Release>:-O3 -Wall -Wextra -Wno-sign-compare -DNDEBUG>
174174
)

CMakePresets.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"ENABLE_OPENGL": true,
1414
"BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN": true,
1515
"BUILD_SENTRY_PLUGIN": true,
16-
"ENABLE_TESTS": true
16+
"ENABLE_TESTS": true,
17+
"CMAKE_C_COMPILER": "clang-20",
18+
"CMAKE_CXX_COMPILER": "clang++-20"
1719
}
1820
},
1921
{
@@ -41,4 +43,4 @@
4143
}
4244
}
4345
]
44-
}
46+
}

src/compositor_ng.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void fill_platform_view_layer_props(
231231
size_t n_mutations,
232232
const struct mat3f *display_to_view_transform,
233233
const struct mat3f *view_to_display_transform,
234-
double device_pixel_ratio
234+
float device_pixel_ratio
235235
) {
236236
(void) view_to_display_transform;
237237

@@ -262,8 +262,8 @@ static void fill_platform_view_layer_props(
262262
* ```
263263
*/
264264

265-
rect.size.x /= device_pixel_ratio;
266-
rect.size.y /= device_pixel_ratio;
265+
rect.size.x /= (double) device_pixel_ratio;
266+
rect.size.y /= (double) device_pixel_ratio;
267267

268268
// okay, now we have the params.finalBoundingRect().x() in aa_back_transformed.x and
269269
// params.finalBoundingRect().y() in aa_back_transformed.y.

src/egl_gbm_render_surface.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,10 @@ static int egl_gbm_render_surface_queue_present(struct render_surface *s, const
655655

656656
LOG_DEBUG(
657657
"using fourcc %c%c%c%c (%s) with modifier 0x%" PRIx64 "\n",
658-
fourcc & 0xFF,
659-
(fourcc >> 8) & 0xFF,
660-
(fourcc >> 16) & 0xFF,
661-
(fourcc >> 24) & 0xFF,
658+
(char) (fourcc & 0xFF),
659+
(char) ((fourcc >> 8) & 0xFF),
660+
(char) ((fourcc >> 16) & 0xFF),
661+
(char) ((fourcc >> 24) & 0xFF),
662662
has_format ? get_pixfmt_info(format)->name : "?",
663663
modifier
664664
);

src/flutter-pi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ static int flutterpi_run(struct flutterpi *flutterpi) {
14521452
window_metrics_event.struct_size = sizeof(FlutterWindowMetricsEvent);
14531453
window_metrics_event.width = (size_t) geometry.view_size.x;
14541454
window_metrics_event.height = (size_t) geometry.view_size.y;
1455-
window_metrics_event.pixel_ratio = geometry.device_pixel_ratio;
1455+
window_metrics_event.pixel_ratio = (double) geometry.device_pixel_ratio;
14561456
window_metrics_event.left = 0;
14571457
window_metrics_event.top = 0;
14581458
window_metrics_event.physical_view_inset_top = 0;

src/platformchannel.c

Lines changed: 126 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <assert.h>
44
#include <ctype.h>
55
#include <errno.h>
6+
#include <float.h>
67
#include <stdbool.h>
78
#include <stdint.h>
89
#include <stdio.h>
910
#include <stdlib.h>
1011
#include <string.h>
11-
#include <float.h>
1212

1313
#include <flutter_embedder.h>
1414

@@ -957,118 +957,147 @@ int platch_decode_json(char *string, struct json_value *out) {
957957
}
958958

959959
int platch_decode(const uint8_t *buffer, size_t size, enum platch_codec codec, struct platch_obj *object_out) {
960-
struct json_value root_jsvalue;
961-
const uint8_t *buffer_cursor = buffer;
962-
size_t remaining = size;
963960
int ok;
964961

965962
if ((size == 0) && (buffer == NULL)) {
966963
object_out->codec = kNotImplemented;
967964
return 0;
968965
}
969966

967+
const uint8_t *buffer_cursor = buffer;
968+
size_t remaining = size;
969+
970970
object_out->codec = codec;
971971
switch (codec) {
972-
case kNotImplemented:
973-
ASSERT_EQUALS(size, 0);
974-
ASSERT_EQUALS(buffer, NULL);
975-
break;
972+
case kNotImplemented: {
973+
if (size != 0) {
974+
return EINVAL;
975+
}
976+
if (buffer != NULL) {
977+
return EINVAL;
978+
}
976979

977-
case kStringCodec:;
978-
/// buffer is a non-null-terminated, UTF8-encoded string.
979-
/// it's really sad we have to allocate a new memory block for this, but we have to since string codec buffers are not null-terminated.
980+
break;
981+
}
980982

981-
char *string;
982-
if (!(string = malloc(size + 1)))
983+
case kStringCodec: {
984+
char *string = malloc(size + 1);
985+
if (string == NULL) {
983986
return ENOMEM;
984-
memcpy(string, buffer, size);
987+
}
988+
989+
strncpy(string, (char *) buffer, size);
985990
string[size] = '\0';
986991

987992
object_out->string_value = string;
988-
989993
break;
990-
case kBinaryCodec:
994+
}
995+
case kBinaryCodec: {
996+
if (size == 0) {
997+
return EINVAL;
998+
}
999+
if (buffer == NULL) {
1000+
return EINVAL;
1001+
}
1002+
9911003
object_out->binarydata = buffer;
9921004
object_out->binarydata_size = size;
993-
9941005
break;
995-
case kJSONMessageCodec:
996-
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &(object_out->json_value));
997-
if (ok != 0)
1006+
}
1007+
case kJSONMessageCodec: {
1008+
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &object_out->json_value);
1009+
if (ok != 0) {
9981010
return ok;
1011+
}
9991012

10001013
break;
1001-
case kJSONMethodCall:;
1002-
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &root_jsvalue);
1003-
if (ok != 0)
1004-
return ok;
1014+
}
1015+
case kJSONMethodCall: {
1016+
struct json_value root;
10051017

1006-
if (root_jsvalue.type != kJsonObject)
1007-
return EBADMSG;
1018+
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &root);
1019+
if (ok != 0) {
1020+
return ok;
1021+
}
10081022

1009-
for (int i = 0; i < root_jsvalue.size; i++) {
1010-
if ((streq(root_jsvalue.keys[i], "method")) && (root_jsvalue.values[i].type == kJsonString)) {
1011-
object_out->method = root_jsvalue.values[i].string_value;
1012-
} else if (streq(root_jsvalue.keys[i], "args")) {
1013-
object_out->json_arg = root_jsvalue.values[i];
1014-
} else
1015-
return EBADMSG;
1023+
if (root.type != kJsonObject) {
1024+
platch_free_json_value(&root, true);
1025+
return EINVAL;
10161026
}
10171027

1018-
platch_free_json_value(&root_jsvalue, true);
1028+
for (int i = 0; i < root.size; i++) {
1029+
if ((streq(root.keys[i], "method")) && (root.values[i].type == kJsonString)) {
1030+
object_out->method = root.values[i].string_value;
1031+
} else if (streq(root.keys[i], "args")) {
1032+
object_out->json_arg = root.values[i];
1033+
} else {
1034+
return EINVAL;
1035+
}
1036+
}
10191037

1038+
platch_free_json_value(&root, true);
10201039
break;
1040+
}
10211041
case kJSONMethodCallResponse: {
1022-
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &root_jsvalue);
1042+
struct json_value root;
1043+
1044+
ok = platch_decode_value_json((char *) buffer, size, NULL, NULL, &root);
10231045
if (ok != 0) {
10241046
return ok;
10251047
}
10261048

1027-
if (root_jsvalue.type != kJsonArray) {
1028-
platch_free_json_value(&root_jsvalue, true);
1029-
return EBADMSG;
1049+
if (root.type != kJsonArray) {
1050+
platch_free_json_value(&root, true);
1051+
return EINVAL;
10301052
}
10311053

1032-
if (root_jsvalue.size == 1) {
1054+
if (root.size == 1) {
10331055
object_out->success = true;
1034-
object_out->json_result = root_jsvalue.array[0];
1035-
platch_free_json_value(&root_jsvalue, true);
1036-
} else if ((root_jsvalue.size == 3) && (root_jsvalue.array[0].type == kJsonString) &&
1037-
((root_jsvalue.array[1].type == kJsonString) || (root_jsvalue.array[1].type == kJsonNull))) {
1056+
object_out->json_result = root.array[0];
1057+
} else if ((root.size == 3) && (root.array[0].type == kJsonString) &&
1058+
((root.array[1].type == kJsonString) || (root.array[1].type == kJsonNull))) {
10381059
object_out->success = false;
1039-
object_out->error_code = root_jsvalue.array[0].string_value;
1040-
object_out->error_msg = root_jsvalue.array[1].string_value;
1041-
object_out->json_error_details = root_jsvalue.array[2];
1042-
platch_free_json_value(&root_jsvalue, true);
1060+
object_out->error_code = root.array[0].string_value;
1061+
object_out->error_msg = root.array[1].string_value;
1062+
object_out->json_error_details = root.array[2];
10431063
} else {
1044-
platch_free_json_value(&root_jsvalue, true);
1045-
return EBADMSG;
1064+
platch_free_json_value(&root, true);
1065+
return EINVAL;
10461066
}
10471067

1068+
platch_free_json_value(&root, true);
10481069
break;
10491070
}
1050-
case kStandardMessageCodec:
1071+
case kStandardMessageCodec: {
10511072
ok = platch_decode_value_std(&buffer_cursor, &remaining, &object_out->std_value);
1052-
if (ok != 0)
1073+
if (ok != 0) {
10531074
return ok;
1075+
}
1076+
10541077
break;
1055-
case kStandardMethodCall:;
1078+
}
1079+
case kStandardMethodCall: {
10561080
struct std_value methodname;
10571081

10581082
ok = platch_decode_value_std(&buffer_cursor, &remaining, &methodname);
1059-
if (ok != 0)
1083+
if (ok != 0) {
10601084
return ok;
1085+
}
1086+
10611087
if (methodname.type != kStdString) {
10621088
platch_free_value_std(&methodname);
1063-
return EBADMSG;
1089+
return EINVAL;
10641090
}
1091+
10651092
object_out->method = methodname.string_value;
10661093

10671094
ok = platch_decode_value_std(&buffer_cursor, &remaining, &object_out->std_arg);
1068-
if (ok != 0)
1095+
if (ok != 0) {
10691096
return ok;
1097+
}
10701098

10711099
break;
1100+
}
10721101
case kStandardMethodCallResponse: {
10731102
ok = _read_u8(&buffer_cursor, (uint8_t *) &object_out->success, &remaining);
10741103
if (ok != 0) {
@@ -1077,8 +1106,9 @@ int platch_decode(const uint8_t *buffer, size_t size, enum platch_codec codec, s
10771106

10781107
if (object_out->success) {
10791108
ok = platch_decode_value_std(&buffer_cursor, &remaining, &(object_out->std_result));
1080-
if (ok != 0)
1109+
if (ok != 0) {
10811110
return ok;
1111+
}
10821112
} else {
10831113
struct std_value error_code, error_msg;
10841114

@@ -1107,9 +1137,10 @@ int platch_decode(const uint8_t *buffer, size_t size, enum platch_codec codec, s
11071137
platch_free_value_std(&object_out->std_error_details);
11081138
platch_free_value_std(&error_code);
11091139
platch_free_value_std(&error_msg);
1110-
return EBADMSG;
1140+
return EINVAL;
11111141
}
11121142
}
1143+
11131144
break;
11141145
}
11151146
default: return EINVAL;
@@ -1128,28 +1159,58 @@ int platch_encode(struct platch_obj *object, uint8_t **buffer_out, size_t *size_
11281159
*buffer_out = NULL;
11291160

11301161
switch (object->codec) {
1131-
case kNotImplemented:
1162+
case kNotImplemented: {
11321163
*size_out = 0;
11331164
*buffer_out = NULL;
11341165
return 0;
1135-
case kStringCodec: size = strlen(object->string_value); break;
1136-
case kBinaryCodec:
1166+
}
1167+
case kStringCodec: {
1168+
*buffer_out = (uint8_t *) strdup(object->string_value);
1169+
if (buffer_out == NULL) {
1170+
return ENOMEM;
1171+
}
1172+
1173+
*size_out = strlen(object->string_value);
1174+
return 0;
1175+
}
1176+
case kBinaryCodec: {
11371177
/// FIXME: Copy buffer instead
11381178
*buffer_out = (uint8_t *) object->binarydata;
11391179
*size_out = object->binarydata_size;
11401180
return 0;
1141-
case kJSONMessageCodec:
1181+
}
1182+
case kJSONMessageCodec: {
11421183
size = platch_calc_value_size_json(&(object->json_value));
11431184
size += 1; // JSONMsgCodec uses sprintf, which null-terminates strings,
11441185
// so lets allocate one more byte for the last null-terminator.
11451186
// this is decremented again in the second switch-case, so flutter
11461187
// doesn't complain about a malformed message.
1188+
1189+
buffer = malloc(size);
1190+
if (buffer == NULL) {
1191+
return ENOMEM;
1192+
}
1193+
1194+
ok = platch_write_value_to_buffer_json(&(object->json_value), &buffer_cursor);
1195+
if (ok != 0) {
1196+
goto free_buffer_and_return_ok;
1197+
}
1198+
11471199
break;
1148-
case kStandardMessageCodec:
1200+
}
1201+
case kStandardMessageCodec: {
11491202
ok = platch_calc_value_size_std(&(object->std_value), &size);
1150-
if (ok != 0)
1203+
if (ok != 0) {
11511204
return ok;
1152-
break;
1205+
}
1206+
1207+
buffer = malloc(size);
1208+
if (buffer == NULL) {
1209+
return ENOMEM;
1210+
}
1211+
1212+
buffer_cursor = buffer;
1213+
}
11531214
case kStandardMethodCall:
11541215
stdmethod.type = kStdString;
11551216
stdmethod.string_value = object->method;
@@ -2254,7 +2315,7 @@ ATTR_PURE bool raw_std_value_equals(const struct raw_std_value *a, const struct
22542315
length = raw_std_value_get_size(a);
22552316
const float *a_floats = raw_std_value_as_float32array(a);
22562317
const float *b_floats = raw_std_value_as_float32array(b);
2257-
2318+
22582319
PRAGMA_DIAGNOSTIC_PUSH
22592320
PRAGMA_DIAGNOSTIC_IGNORED("-Wfloat-equal")
22602321
for (int i = 0; i < length; i++) {

0 commit comments

Comments
 (0)