From 2a36ddeeb030dfa34d10bd5c2bffff9018d84214 Mon Sep 17 00:00:00 2001 From: Hannes Winkler Date: Mon, 16 Sep 2024 20:39:25 +0000 Subject: [PATCH] fix / ignore some more warnings --- .codechecker.json | 2 ++ CMakeLists.txt | 1 + src/compositor_ng.c | 2 +- src/egl_gbm_render_surface.c | 7 +++++-- src/flutter-pi.c | 2 +- src/modesetting.c | 2 +- src/platformchannel.c | 5 ++--- src/pluginregistry.c | 17 ++++++++++------- src/util/macros.h | 9 +++++++++ src/vk_renderer.c | 2 +- src/window.c | 14 +++++++++----- .../mesa3d/include/mesa3d}/dynarray.h | 2 -- 12 files changed, 42 insertions(+), 23 deletions(-) rename {src/util => third_party/mesa3d/include/mesa3d}/dynarray.h (99%) diff --git a/.codechecker.json b/.codechecker.json index 2dc05b09..790b678d 100644 --- a/.codechecker.json +++ b/.codechecker.json @@ -10,6 +10,8 @@ "clang-diagnostic-sign-compare", "-d", "clang-diagnostic-implicit-int-float-conversion", + "-d", + "clang-diagnostic-switch-enum", "--analyzers", "clangsa", "clang-tidy", diff --git a/CMakeLists.txt b/CMakeLists.txt index 687512d4..e507dca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,7 @@ target_link_libraries(flutterpi_module PUBLIC target_include_directories(flutterpi_module PUBLIC ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/third_party/mesa3d/include ${CMAKE_SOURCE_DIR}/third_party/flutter_embedder_header/include ) diff --git a/src/compositor_ng.c b/src/compositor_ng.c index e56515ec..dcbf6b9c 100644 --- a/src/compositor_ng.c +++ b/src/compositor_ng.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "cursor.h" @@ -33,7 +34,6 @@ #include "surface.h" #include "tracer.h" #include "util/collection.h" -#include "util/dynarray.h" #include "util/logging.h" #include "util/refcounting.h" #include "window.h" diff --git a/src/egl_gbm_render_surface.c b/src/egl_gbm_render_surface.c index 853987a5..74b0ae01 100644 --- a/src/egl_gbm_render_surface.c +++ b/src/egl_gbm_render_surface.c @@ -171,7 +171,8 @@ static int egl_gbm_render_surface_init( GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT ); if (gbm_surface == NULL) { - ok = errno ? errno : EIO; + ok = errno; + if (allowed_modifiers != NULL) { LOG_ERROR( "Couldn't create GBM surface for rendering. gbm_surface_create_with_modifiers: %s, gbm_surface_create: %s\n", @@ -182,7 +183,9 @@ static int egl_gbm_render_surface_init( LOG_ERROR("Couldn't create GBM surface for rendering. gbm_surface_create: %s\n", strerror(ok)); } - return ok; + // Return an error != 0 in any case, so the caller doesn't think + // that the surface was created successfully. + return ok ? ok : EIO; } } diff --git a/src/flutter-pi.c b/src/flutter-pi.c index aee6983d..c9a87468 100644 --- a/src/flutter-pi.c +++ b/src/flutter-pi.c @@ -770,7 +770,7 @@ static int on_execute_flutter_task(void *userdata) { result = flutterpi->flutter.procs.RunTask(flutterpi->flutter.engine, task); if (result != kSuccess) { - LOG_ERROR("Error running platform task. FlutterEngineRunTask: %d\n", result); + LOG_ERROR("Error running platform task. FlutterEngineRunTask: %u\n", result); free(task); return EINVAL; } diff --git a/src/modesetting.c b/src/modesetting.c index c96bb9f1..29a4024f 100644 --- a/src/modesetting.c +++ b/src/modesetting.c @@ -2268,7 +2268,7 @@ struct kms_req_builder *drmdev_create_request_builder(struct drmdev *drmdev, uin } if (crtc == NULL) { - LOG_ERROR("Invalid CRTC id: %" PRId32 "\n", crtc_id); + LOG_ERROR("Invalid CRTC id: %" PRIu32 "\n", crtc_id); goto fail_unlock; } diff --git a/src/platformchannel.c b/src/platformchannel.c index 77a70aa3..020727c0 100644 --- a/src/platformchannel.c +++ b/src/platformchannel.c @@ -959,9 +959,8 @@ int platch_decode_json(char *string, struct json_value *out) { int platch_decode(const uint8_t *buffer, size_t size, enum platch_codec codec, struct platch_obj *object_out) { int ok; - if ((size == 0) && (buffer == NULL)) { - object_out->codec = kNotImplemented; - return 0; + if (codec != kNotImplemented && ((size == 0) || (buffer == NULL))) { + return EINVAL; } const uint8_t *buffer_cursor = buffer; diff --git a/src/pluginregistry.c b/src/pluginregistry.c index d3d325b6..eecd6807 100644 --- a/src/pluginregistry.c +++ b/src/pluginregistry.c @@ -392,14 +392,17 @@ int plugin_registry_set_receiver(const char *channel, enum platch_codec codec, p int plugin_registry_remove_receiver_v2_locked(struct plugin_registry *registry, const char *channel) { struct platch_obj_cb_data *data; - data = get_cb_data_by_channel_locked(registry, channel); - if (data == NULL) { - return EINVAL; - } + // clang analyzer reports false-positives for using deallocated memory here. + ANALYZER_SUPPRESS({ + data = get_cb_data_by_channel_locked(registry, channel); + if (data == NULL) { + return EINVAL; + } - list_del(&data->entry); - free(data->channel); - free(data); + list_del(&data->entry); + free(data->channel); + free(data); + }); return 0; } diff --git a/src/util/macros.h b/src/util/macros.h index 80880a24..c7648fd0 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -122,6 +122,9 @@ #if __has_attribute(noreturn) #define HAVE_FUNC_ATTRIBUTE_NORETURN #endif +#if __has_attribute(suppress) + #define HAVE_STMT_ATTRIBUTE_SUPPRESS +#endif /** * __builtin_expect macros @@ -405,6 +408,12 @@ #define ATTR_NOINLINE #endif +#if HAVE_STMT_ATTRIBUTE_SUPPRESS + #define ANALYZER_SUPPRESS(stmt) __attribute__((suppress)) stmt +#else + #define ANALYZER_SUPPRESS(stmt) stmt +#endif + /** * Check that STRUCT::FIELD can hold MAXVAL. We use a lot of bitfields * in Mesa/gallium. We have to be sure they're of sufficient size to diff --git a/src/vk_renderer.c b/src/vk_renderer.c index f60b762d..3c2abe5a 100644 --- a/src/vk_renderer.c +++ b/src/vk_renderer.c @@ -52,7 +52,7 @@ static VkBool32 on_debug_utils_message( UNUSED void *userdata ) { LOG_DEBUG( - "[%s] (%d, %s) %s (queues: %d, cmdbufs: %d, objects: %d)\n", + "[%s] (%d, %s) %s (queues: %u, cmdbufs: %u, objects: %u)\n", severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT ? "VERBOSE" : severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT ? "INFO" : severity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT ? "WARNING" : diff --git a/src/window.c b/src/window.c index 7ce56c97..920878ee 100644 --- a/src/window.c +++ b/src/window.c @@ -1429,11 +1429,15 @@ static struct render_surface *kms_window_get_render_surface_internal(struct wind drm_plane_for_each_modified_format(plane, count_modifiers_for_pixel_format, &context); n_allowed_modifiers = context.n_modifiers; - allowed_modifiers = calloc(n_allowed_modifiers, sizeof(*context.modifiers)); - context.modifiers = allowed_modifiers; + if (n_allowed_modifiers) { + allowed_modifiers = calloc(n_allowed_modifiers, sizeof(*context.modifiers)); + context.modifiers = allowed_modifiers; - // Next, fill context.modifiers with the allowed modifiers. - drm_plane_for_each_modified_format(plane, extract_modifiers_for_pixel_format, &context); + // Next, fill context.modifiers with the allowed modifiers. + drm_plane_for_each_modified_format(plane, extract_modifiers_for_pixel_format, &context); + } else { + allowed_modifiers = NULL; + } break; } } @@ -1754,7 +1758,7 @@ static EGLSurface dummy_window_get_egl_surface(struct window *window) { if (render_surface == NULL) { return EGL_NO_SURFACE; } - + return egl_gbm_render_surface_get_egl_surface(CAST_EGL_GBM_RENDER_SURFACE(render_surface)); } else { return EGL_NO_SURFACE; diff --git a/src/util/dynarray.h b/third_party/mesa3d/include/mesa3d/dynarray.h similarity index 99% rename from src/util/dynarray.h rename to third_party/mesa3d/include/mesa3d/dynarray.h index 2d9f2101..220ea57f 100644 --- a/src/util/dynarray.h +++ b/third_party/mesa3d/include/mesa3d/dynarray.h @@ -32,8 +32,6 @@ #include #include -#include "macros.h" - #ifdef __cplusplus extern "C" { #endif