From a813091fb47796ab658e4573907f9954dce88944 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 14 Oct 2024 15:45:31 +0100 Subject: [PATCH] misc: fix/silence a bunch of linter warnings Signed-off-by: Yuxuan Shui --- src/backend/backend.c | 1 - src/c2.h | 2 ++ src/common.h | 6 ------ src/config.c | 13 ++++++++----- src/config.h | 11 +++-------- src/config_libconfig.c | 8 +------- src/dbus.c | 6 +++--- src/err.h | 37 ------------------------------------- src/event.c | 1 - src/options.c | 1 - src/picom.c | 25 +++++++++++++------------ src/picom.h | 1 - src/region.h | 7 ++++--- src/renderer/layout.h | 2 +- src/rtkit.h | 2 ++ src/transition/script.c | 9 +++++---- src/transition/script.h | 2 +- src/utils/dynarr.h | 2 +- src/utils/misc.h | 6 +++--- src/wm/win.c | 19 +++++++++++++------ src/wm/win.h | 1 + src/x.h | 5 +++-- 22 files changed, 64 insertions(+), 103 deletions(-) delete mode 100644 src/err.h diff --git a/src/backend/backend.c b/src/backend/backend.c index 6eae7386..1f332b35 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -11,7 +11,6 @@ #include "config.h" #include "log.h" #include "region.h" -#include "renderer/layout.h" #include "wm/win.h" #include "x.h" diff --git a/src/c2.h b/src/c2.h index fb6a86eb..ac425865 100644 --- a/src/c2.h +++ b/src/c2.h @@ -72,6 +72,7 @@ c2_condition *c2_condition_list_entry(struct list_node *list); /// Create a new condition list with a single condition that is always true. c2_condition *c2_new_true(struct list_node *list); +// NOLINTBEGIN(bugprone-macro-parentheses) #define c2_condition_list_foreach(list, i) \ for (c2_condition *i = \ list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->next); \ @@ -86,6 +87,7 @@ c2_condition *c2_new_true(struct list_node *list); list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->next), \ *n = c2_condition_list_next(list, i); \ i; i = n, n = c2_condition_list_next(list, i)) +// NOLINTEND(bugprone-macro-parentheses) /** * Destroy a condition list. diff --git a/src/common.h b/src/common.h index ebe9df49..21170b67 100644 --- a/src/common.h +++ b/src/common.h @@ -62,12 +62,6 @@ struct atom; struct conv; -/// Linked list type of atoms. -typedef struct _latom { - xcb_atom_t atom; - struct _latom *next; -} latom_t; - struct shader_info { char *key; char *source; diff --git a/src/config.c b/src/config.c index c9f4645d..6c7e58d9 100644 --- a/src/config.c +++ b/src/config.c @@ -211,12 +211,14 @@ static conv *parse_blur_kern(const char *src, const char **endptr) { // Get matrix width and height double val = 0.0; - if (src == (pc = parse_readnum(src, &val))) { + pc = parse_readnum(src, &val); + if (src == pc) { goto err1; } src = pc; width = (int)val; - if (src == (pc = parse_readnum(src, &val))) { + pc = parse_readnum(src, &val); + if (src == pc) { goto err1; } src = pc; @@ -247,7 +249,8 @@ static conv *parse_blur_kern(const char *src, const char **endptr) { matrix->data[i] = 1; continue; } - if (src == (pc = parse_readnum(src, &val))) { + pc = parse_readnum(src, &val); + if (src == pc) { goto err2; } src = pc; @@ -356,7 +359,7 @@ struct conv **parse_blur_kern_lst(const char *src, int *count) { *count = 0; for (unsigned int i = 0; i < sizeof(CONV_KERN_PREDEF) / sizeof(CONV_KERN_PREDEF[0]); ++i) { - if (!strcmp(CONV_KERN_PREDEF[i].name, src)) { + if (strcmp(CONV_KERN_PREDEF[i].name, src) == 0) { return parse_blur_kern_lst(CONV_KERN_PREDEF[i].kern_str, count); } } @@ -622,7 +625,7 @@ void *parse_window_shader_prefix(const char *src, const char **end, void *user_d *end = endptr + 1; return shader_source; } -void *parse_window_shader_prefix_with_cwd(const char *src, const char **end, void *) { +void *parse_window_shader_prefix_with_cwd(const char *src, const char **end, void * /*data*/) { scoped_charp cwd = getcwd(NULL, 0); return parse_window_shader_prefix(src, end, cwd); } diff --git a/src/config.h b/src/config.h index c0d51eb0..40628385 100644 --- a/src/config.h +++ b/src/config.h @@ -462,14 +462,9 @@ void parse_debug_options(struct debug_options *); const char *xdg_config_home(void); char **xdg_config_dirs(void); -/// Parse a configuration file -/// Returns the actually config_file name used, allocated on heap -/// Outputs: -/// shadow_enable = whether shadow is enabled globally -/// fading_enable = whether fading is enabled globally -/// win_option_mask = whether option overrides for specific window type is set for given -/// options -/// hasneg = whether the convolution kernel has negative values +/// Parse a configuration file from default location. +/// +/// @return if config is successfully parsed. bool parse_config_libconfig(options_t *, const char *config_file); /// Parse a configuration file is that is enabled, also initialize the winopt_mask with diff --git a/src/config_libconfig.c b/src/config_libconfig.c index bec29d4f..859a18b4 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -666,13 +666,7 @@ resolve_include(config_t *cfg, const char *include_dir, const char *path, const return ret; } -/** - * Parse a configuration file from default location. - * - * Returns if config is successfully parsed. - */ -bool parse_config_libconfig(options_t *opt, const char *config_file) { - +bool parse_config_libconfig(options_t *opt, const char *config_file) { /*NOLINT(readability-function-cognitive-complexity)*/ const char *deprecation_message = "option has been deprecated. Please remove it from your configuration file. " "If you encounter any problems without this feature, please feel free to " diff --git a/src/dbus.c b/src/dbus.c index 1112a362..55233471 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -75,7 +75,7 @@ typedef uint32_t cdbus_enum_t; #define PICOM_WINDOW_INTERFACE "picom.Window" #define PICOM_COMPOSITOR_INTERFACE "picom.Compositor" -static DBusHandlerResult cdbus_process(DBusConnection *conn, DBusMessage *m, void *); +static DBusHandlerResult cdbus_process(DBusConnection *conn, DBusMessage *m, void *ud); static DBusHandlerResult cdbus_process_windows(DBusConnection *c, DBusMessage *msg, void *ud); static dbus_bool_t cdbus_callback_add_timeout(DBusTimeout *timeout, void *data); @@ -307,8 +307,8 @@ void cdbus_io_callback(EV_P attr_unused, ev_io *w, int revents) { flags |= DBUS_WATCH_WRITABLE; } dbus_watch_handle(dw->dw, flags); - while (dbus_connection_dispatch(dw->cd->dbus_conn) != DBUS_DISPATCH_COMPLETE) - ; + while (dbus_connection_dispatch(dw->cd->dbus_conn) != DBUS_DISPATCH_COMPLETE) { + } } /** diff --git a/src/err.h b/src/err.h deleted file mode 100644 index f989bf9c..00000000 --- a/src/err.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 -// Copyright (c) 2019 Yuxuan Shui - -#pragma once -#include -#include -#include "compiler.h" - -// Functions for error reporting, adopted from Linux - -// INFO in user space we can probably be more liberal about what pointer we consider -// error. e.g. In x86_64 Linux, all addresses with the highest bit set is invalid in user -// space. -#define MAX_ERRNO 4095 - -static inline void *must_use ERR_PTR(intptr_t err) { - return (void *)err; -} - -static inline intptr_t must_use PTR_ERR(void *ptr) { - return (intptr_t)ptr; -} - -static inline bool must_use IS_ERR(void *ptr) { - return unlikely((uintptr_t)ptr > (uintptr_t)-MAX_ERRNO); -} - -static inline bool must_use IS_ERR_OR_NULL(void *ptr) { - return unlikely(!ptr) || IS_ERR(ptr); -} - -static inline intptr_t must_use PTR_ERR_OR_ZERO(void *ptr) { - if (IS_ERR(ptr)) { - return PTR_ERR(ptr); - } - return 0; -} diff --git a/src/event.c b/src/event.c index 6b789c5b..1b061816 100644 --- a/src/event.c +++ b/src/event.c @@ -21,7 +21,6 @@ #include "log.h" #include "picom.h" #include "region.h" -#include "utils/dynarr.h" #include "wm/defs.h" #include "wm/wm.h" #include "x.h" diff --git a/src/options.c b/src/options.c index 90f0e611..3324d7f1 100644 --- a/src/options.c +++ b/src/options.c @@ -14,7 +14,6 @@ #include "backend/backend.h" #include "c2.h" -#include "common.h" #include "config.h" #include "log.h" #include "options.h" diff --git a/src/picom.c b/src/picom.c index 0c21ef82..fb36a8b4 100644 --- a/src/picom.c +++ b/src/picom.c @@ -57,9 +57,7 @@ #include "renderer/command_builder.h" #include "renderer/layout.h" #include "renderer/renderer.h" -#include "utils/dynarr.h" #include "utils/file_watch.h" -#include "utils/kernel.h" #include "utils/list.h" #include "utils/misc.h" #include "utils/statistics.h" @@ -1902,16 +1900,17 @@ static struct window_options win_options_from_config(const struct options *opts) return ret; } -/** - * Initialize a session. - * - * @param argc number of command line arguments - * @param argv command line arguments - * @param dpy the X Display - * @param config_file the path to the config file - * @param all_xerrors whether we should report all X errors - * @param fork whether we will fork after initialization - */ +// NOLINTBEGIN(readability-function-cognitive-complexity) + +/// Initialize a session. +/// +/// @param argc number of command line arguments +/// @param argv command line arguments +/// @param dpy the X Display +/// @param config_file the path to the config file +/// @param all_xerrors whether we should report all X errors +/// @param fork whether we will fork after initialization +/// static session_t *session_init(int argc, char **argv, Display *dpy, const char *config_file, bool all_xerrors, bool fork) { static const session_t s_def = { @@ -2403,6 +2402,8 @@ err: return NULL; } +// NOLINTEND(readability-function-cognitive-complexity) + /** * Destroy a session. * diff --git a/src/picom.h b/src/picom.h index 49172d67..925eda34 100644 --- a/src/picom.h +++ b/src/picom.h @@ -19,7 +19,6 @@ #include "common.h" #include "config.h" #include "log.h" // XXX clean up -#include "region.h" #include "wm/win.h" #include "x.h" diff --git a/src/region.h b/src/region.h index ff60a698..ba9ad678 100644 --- a/src/region.h +++ b/src/region.h @@ -84,7 +84,8 @@ static inline rect_t *from_x_rects(int nrects, const xcb_rectangle_t *rects) { /** * Resize a region. */ -static inline void _resize_region(const region_t *region, region_t *output, int dx, int dy) { +static inline void +resize_region_inner(const region_t *region, region_t *output, int dx, int dy) { if (!region || !output) { return; } @@ -122,12 +123,12 @@ static inline void _resize_region(const region_t *region, region_t *output, int static inline region_t resize_region(const region_t *region, int dx, int dy) { region_t ret; pixman_region32_init(&ret); - _resize_region(region, &ret, dx, dy); + resize_region_inner(region, &ret, dx, dy); return ret; } static inline void resize_region_in_place(region_t *region, int dx, int dy) { - return _resize_region(region, region, dx, dy); + return resize_region_inner(region, region, dx, dy); } static inline rect_t region_translate_rect(rect_t rect, ivec2 origin) { diff --git a/src/renderer/layout.h b/src/renderer/layout.h index 4af727e6..6063a60a 100644 --- a/src/renderer/layout.h +++ b/src/renderer/layout.h @@ -85,7 +85,7 @@ struct layout_manager; /// layouts, with its size chosen at creation time. Calling this will push at new layout /// at the end of the ring buffer, and remove the oldest layout if the buffer is full. void layout_manager_append_layout(struct layout_manager *lm, struct wm *wm, - uint64_t root_image_generation, ivec2 size); + uint64_t root_pixmap_generation, ivec2 size); /// Get the layout `age` frames into the past. Age `0` is the most recently appended /// layout. struct layout *layout_manager_layout(struct layout_manager *lm, unsigned age); diff --git a/src/rtkit.h b/src/rtkit.h index a5b04e88..ee23e7c4 100644 --- a/src/rtkit.h +++ b/src/rtkit.h @@ -5,6 +5,8 @@ #include #include +#include "compiler.h" + #ifdef CONFIG_DBUS #include diff --git a/src/transition/script.c b/src/transition/script.c index 9db503ee..540ccd65 100644 --- a/src/transition/script.c +++ b/src/transition/script.c @@ -1068,7 +1068,7 @@ script_compile(config_setting_t *setting, struct script_parse_config cfg, char * } char *script_to_c(const struct script *script, const struct script_output_info *outputs) { - char **buf = dynarr_new(char *, script->len * 40); + char **buf = dynarr_new(char *, (size_t)script->len * 40); char *tmp = NULL; casprintf(&tmp, "{\n" " static const struct instruction instrs[] = {\n"); @@ -1135,15 +1135,16 @@ char *script_to_c(const struct script *script, const struct script_output_info * } void script_specialize(struct script *script, - const struct script_specialization_context *spec, unsigned n_context) { + const struct script_specialization_context *context, + unsigned n_context) { for (unsigned i = 0; i < script->len; i++) { if (script->instrs[i].type != INST_LOAD_CTX) { continue; } for (unsigned j = 0; j < n_context; j++) { - if (script->instrs[i].ctx == spec[j].offset) { + if (script->instrs[i].ctx == context[j].offset) { script->instrs[i].type = INST_IMM; - script->instrs[i].imm = spec[j].value; + script->instrs[i].imm = context[j].value; break; } } diff --git a/src/transition/script.h b/src/transition/script.h index ec839184..f5955a01 100644 --- a/src/transition/script.h +++ b/src/transition/script.h @@ -72,7 +72,7 @@ unsigned script_elapsed_slot(const struct script *script); /// Specialize a script instance with a context. During evaluation of the resulting /// script, what would have been read from the context will be replaced with the hardcoded /// value in the specialization context. -void script_specialize(struct script *instance, +void script_specialize(struct script *script, const struct script_specialization_context *context, unsigned n_context); diff --git a/src/utils/dynarr.h b/src/utils/dynarr.h index 846900d6..2e39d9c5 100644 --- a/src/utils/dynarr.h +++ b/src/utils/dynarr.h @@ -67,7 +67,7 @@ static inline void dynarr_remove_swap_impl(size_t size, void *arr, size_t idx) { } /// Create a new dynamic array with capacity `cap` for type `type`. -#define dynarr_new(type, cap) ((type *)dynarr_new_impl(sizeof(type), cap)) +#define dynarr_new(type, cap) ((type *)dynarr_new_impl(sizeof(type), (cap))) /// Free a dynamic array, destructing each element with `dtor`. #define dynarr_free(arr, dtor) \ do { \ diff --git a/src/utils/misc.h b/src/utils/misc.h index 48d1702b..1475a196 100644 --- a/src/utils/misc.h +++ b/src/utils/misc.h @@ -83,8 +83,8 @@ safe_isinf(double a) { auto __assert_in_range_tmp attr_unused = (var); \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wtype-limits\""); \ - assert(__assert_in_range_tmp >= lower); \ - assert(__assert_in_range_tmp <= upper); \ + assert(__assert_in_range_tmp >= (lower)); \ + assert(__assert_in_range_tmp <= (upper)); \ _Pragma("GCC diagnostic pop"); \ } while (0) @@ -95,7 +95,7 @@ safe_isinf(double a) { auto __tmp attr_unused = (var); \ _Pragma("GCC diagnostic push"); \ _Pragma("GCC diagnostic ignored \"-Wtype-limits\""); \ - assert(__tmp >= lower); \ + assert(__tmp >= (lower)); \ _Pragma("GCC diagnostic pop"); \ } while (0) diff --git a/src/wm/win.c b/src/wm/win.c index 67d893e2..96a820e7 100644 --- a/src/wm/win.c +++ b/src/wm/win.c @@ -1604,7 +1604,7 @@ void win_destroy_start(struct win *w) { // Update state flags of a managed window w->state = WSTATE_DESTROYED; - w->opacity = 0.0f; + w->opacity = 0.0F; w->a.map_state = XCB_MAP_STATE_UNMAPPED; w->in_openclose = true; } @@ -1630,7 +1630,7 @@ void unmap_win_start(struct win *w) { w->a.map_state = XCB_MAP_STATE_UNMAPPED; w->state = WSTATE_UNMAPPED; - w->opacity = 0.0f; + w->opacity = 0.0F; } struct win_script_context win_script_context_prepare(struct session *ps, struct win *w) { @@ -1812,13 +1812,17 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d if (trigger == ANIMATION_TRIGGER_INVALID) { // No state changes, if there's a animation running, we just continue it. return win_advance_animation(w, delta_t, &win_ctx); - } else if (w->running_animation_instance && - (w->running_animation.suppressions & (1 << trigger)) != 0) { + } + + if (w->running_animation_instance && + (w->running_animation.suppressions & (1 << trigger)) != 0) { log_debug("Not starting animation %s for window %#010x (%s) because it " "is being suppressed.", animation_trigger_names[trigger], win_id(w), w->name); return win_advance_animation(w, delta_t, &win_ctx); - } else if (w->animation_block[trigger] > 0) { + } + + if (w->animation_block[trigger] > 0) { log_debug("Not starting animation %s for window %#010x (%s) because it " "is blocked.", animation_trigger_names[trigger], win_id(w), w->name); @@ -1847,6 +1851,9 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d w->saved_win_image = NULL; } if (ps->drivers & DRIVER_NVIDIA) { + // NVIDIA doesn't like us grabbing the new pixmap before releasing + // the old one. So we copy the content of the old pixmap so we can + // release it. if (w->win_image != NULL) { w->saved_win_image = ps->backend_data->ops.new_image( ps->backend_data, BACKEND_IMAGE_FORMAT_PIXMAP, @@ -2117,7 +2124,7 @@ void win_set_properties_stale(struct win *w, const xcb_atom_t *props, int nprops // Reallocate if necessary if (new_capacity > w->stale_props_capacity) { w->stale_props = - realloc(w->stale_props, new_capacity * sizeof(*w->stale_props)); + crealloc(w->stale_props, new_capacity * sizeof(*w->stale_props)); // Clear the content of the newly allocated bytes memset(w->stale_props + w->stale_props_capacity, 0, diff --git a/src/wm/win.h b/src/wm/win.h index edee97f4..46e76884 100644 --- a/src/wm/win.h +++ b/src/wm/win.h @@ -237,6 +237,7 @@ struct win_script_context { double monitor_x, monitor_y; double monitor_width, monitor_height; }; +// NOLINTNEXTLINE(bugprone-sizeof-expression) static_assert(SCRIPT_CTX_PLACEHOLDER_BASE > sizeof(struct win_script_context), "win_script_context too large"); diff --git a/src/x.h b/src/x.h index 240b64be..732c4329 100644 --- a/src/x.h +++ b/src/x.h @@ -122,6 +122,7 @@ struct x_monitors { }; #define XCB_AWAIT_VOID(func, c, ...) \ + /* NOLINTBEGIN(bugprone-assignment-in-if-condition) */ \ ({ \ bool __success = true; \ __auto_type __e = xcb_request_check(c, func##_checked(c, __VA_ARGS__)); \ @@ -132,7 +133,7 @@ struct x_monitors { __success = false; \ } \ __success; \ - }) + }) /* NOLINTEND(bugprone-assignment-in-if-condition) */ #define XCB_AWAIT(func, c, ...) \ ({ \ @@ -460,7 +461,7 @@ void x_update_monitors_async(struct x_connection *, struct x_monitors *); /// Free memory allocated for a `struct x_monitors`. void x_free_monitor_info(struct x_monitors *); -uint32_t attr_deprecated xcb_generate_id(xcb_connection_t *c); +uint32_t attr_deprecated xcb_generate_id(xcb_connection_t *c); // NOLINT(readability-redundant-declaration) /// Ask X server to send us a notification for the next end of vblank. void x_request_vblank_event(struct x_connection *c, xcb_window_t window, uint64_t msc);