Skip to content

Commit

Permalink
misc: fix/silence a bunch of linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Oct 14, 2024
1 parent 3deb3f2 commit a813091
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 103 deletions.
1 change: 0 additions & 1 deletion src/backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "config.h"
#include "log.h"
#include "region.h"
#include "renderer/layout.h"
#include "wm/win.h"
#include "x.h"

Expand Down
2 changes: 2 additions & 0 deletions src/c2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand All @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 3 additions & 8 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
6 changes: 3 additions & 3 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
}
}

/**
Expand Down
37 changes: 0 additions & 37 deletions src/err.h

This file was deleted.

1 change: 0 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "backend/backend.h"
#include "c2.h"
#include "common.h"
#include "config.h"
#include "log.h"
#include "options.h"
Expand Down
25 changes: 13 additions & 12 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -2403,6 +2402,8 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
return NULL;
}

// NOLINTEND(readability-function-cognitive-complexity)

/**
* Destroy a session.
*
Expand Down
1 change: 0 additions & 1 deletion src/picom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 4 additions & 3 deletions src/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/rtkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <stdbool.h>
#include <sys/types.h>

#include "compiler.h"

#ifdef CONFIG_DBUS

#include <dbus/dbus.h>
Expand Down
9 changes: 5 additions & 4 deletions src/transition/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/transition/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/dynarr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down
6 changes: 3 additions & 3 deletions src/utils/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Loading

0 comments on commit a813091

Please sign in to comment.