Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some warnings (gint formatting, size_t/int mix, etc) #1424

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void dbus_cb_fdn_methods(GDBusConnection *connection,
GDBusMethodInvocation *invocation,
gpointer user_data)
{

struct dbus_method *m = bsearch(method_name,
methods_fdn,
G_N_ELEMENTS(methods_fdn),
Expand Down Expand Up @@ -225,7 +224,6 @@ void dbus_cb_dunst_methods(GDBusConnection *connection,
GDBusMethodInvocation *invocation,
gpointer user_data)
{

struct dbus_method *m = bsearch(method_name,
methods_dunst,
G_N_ELEMENTS(methods_dunst),
Expand All @@ -236,8 +234,7 @@ void dbus_cb_dunst_methods(GDBusConnection *connection,
m->method(connection, sender, parameters, invocation);
} else {
LOG_M("Unknown method name: '%s' (sender: '%s').",
method_name,
sender);
method_name, sender);
}
}

Expand Down Expand Up @@ -450,7 +447,7 @@ static void gradient_entry(const struct gradient *grad, GVariantDict *dict, cons
}

char **strv = g_malloc((grad->length + 1) * sizeof(char *));
for (int i = 0; i < grad->length; i++) {
for (size_t i = 0; i < grad->length; i++) {
char buf[10];
if (color_to_string(grad->colors[i], buf))
strv[i] = g_strdup(buf);
Expand Down Expand Up @@ -669,7 +666,7 @@ static void dbus_cb_GetCapabilities(
g_variant_builder_add(builder, "s", "body-hyperlinks");
g_variant_builder_add(builder, "s", "icon-static");

for (int i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i)
for (size_t i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i)
g_variant_builder_add(builder, "s", stack_tag_hints[i]);

// Since markup isn't a global variable anymore, look it up in the
Expand Down Expand Up @@ -761,7 +758,7 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
*
* Only accept to first one we find.
*/
for (int i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i) {
for (size_t i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i) {
if ((dict_value = g_variant_lookup_value(hints, stack_tag_hints[i], G_VARIANT_TYPE_STRING))) {
n->stack_tag = g_variant_dup_string(dict_value, NULL);
g_variant_unref(dict_value);
Expand Down Expand Up @@ -862,7 +859,7 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
size_t length = g_strv_length(cols);
struct gradient *grad = gradient_alloc(length);

for (int i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
if (!string_parse_color(cols[i], &grad->colors[i])) {
g_free(grad);
goto end;
Expand Down Expand Up @@ -903,7 +900,6 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV

void signal_length_propertieschanged(void)
{

static unsigned int last_displayed = 0;
static unsigned int last_history = 0;
static unsigned int last_waiting = 0;
Expand Down Expand Up @@ -1207,7 +1203,7 @@ gboolean dbus_cb_dunst_Properties_Set(GDBusConnection *connection,


static const GDBusInterfaceVTable interface_vtable_fdn = {
dbus_cb_fdn_methods
dbus_cb_fdn_methods,
};

static const GDBusInterfaceVTable interface_vtable_dunst = {
Expand Down
4 changes: 2 additions & 2 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void gradient_pattern(struct gradient *grad)
grad->colors[0].a);
} else {
grad->pattern = cairo_pattern_create_linear(0, 0, 1, 0);
for (int i = 0; i < grad->length; i++) {
for (size_t i = 0; i < grad->length; i++) {
double offset = i / (double)(grad->length - 1);
cairo_pattern_add_color_stop_rgba(grad->pattern,
offset,
Expand All @@ -129,7 +129,7 @@ char *gradient_to_string(const struct gradient *grad)
int max = grad->length * 11 + 1;
char *buf = g_malloc(max);

for (int i = 0, j = 0; i < grad->length; i++) {
for (size_t i = 0, j = 0; i < grad->length; i++) {
j += g_snprintf(buf + j, max - j, "#%02x%02x%02x%02x",
(int)(grad->colors[i].r * 255),
(int)(grad->colors[i].g * 255),
Expand Down
7 changes: 6 additions & 1 deletion src/dunst.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ static gboolean run(void *data)
gint64 sleep = timeout_at - now;
sleep = MAX(sleep, 1000); // Sleep at least 1ms

LOG_D("Sleeping for %li ms", sleep/1000);
LOG_D("Sleeping for %"G_GINT64_FORMAT" ms", sleep/1000);

next_timeout_id = g_timeout_add(sleep/1000, run, NULL);
}
Expand All @@ -179,6 +179,8 @@ static gboolean run(void *data)

gboolean pause_signal(gpointer data)
{
(void)data;

dunst_status_int(S_PAUSE_LEVEL, MAX_PAUSE_LEVEL);
wake_up();

Expand All @@ -187,6 +189,8 @@ gboolean pause_signal(gpointer data)

gboolean unpause_signal(gpointer data)
{
(void)data;

dunst_status_int(S_PAUSE_LEVEL, 0);
wake_up();

Expand All @@ -195,6 +199,7 @@ gboolean unpause_signal(gpointer data)

gboolean quit_signal(gpointer data)
{
(void)data;
g_main_loop_quit(mainloop);

return G_SOURCE_CONTINUE;
Expand Down
4 changes: 2 additions & 2 deletions src/icon-lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void get_theme_path(void) {

add_paths_from_env(theme_path, "XDG_DATA_DIRS", "icons", "/usr/local/share/:/usr/share/");
g_ptr_array_add(theme_path, g_strdup("/usr/share/pixmaps"));
for (int i = 0; i < theme_path->len; i++) {
for (size_t i = 0; i < theme_path->len; i++) {
LOG_D("Theme locations: %s", (char*)theme_path->pdata[i]);
}
}
Expand All @@ -179,7 +179,7 @@ int load_icon_theme(char *name) {
get_theme_path();
}

for (int i = 0; i < theme_path->len; i++) {
for (size_t i = 0; i < theme_path->len; i++) {
int theme_index = load_icon_theme_from_dir(theme_path->pdata[i], name);
if (theme_index != -1)
return theme_index;
Expand Down
8 changes: 7 additions & 1 deletion src/icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ char *get_path_from_icon_name(const char *iconname, int size)
return path;
}

static void icon_destroy(guchar *pixels, gpointer data)
{
(void)data;
g_free(pixels);
}

GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int min_size, int max_size)
{
ASSERT_OR_RET(data, NULL);
Expand Down Expand Up @@ -351,7 +357,7 @@ GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int mi
width,
height,
rowstride,
(GdkPixbufDestroyNotify) g_free,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fwsmit I replaced this g_free with an actual function taking two arguments since it just seemed wrong. Was this supposed to free both the pixels and data_pb?

icon_destroy,
data_pb);
if (!pixbuf) {
/* Dear user, I'm sorry, I'd like to give you a more specific
Expand Down
2 changes: 2 additions & 0 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ static void dunst_log_handler(
const gchar *message,
gpointer testing)
{
(void)log_domain;

if (testing)
log_level = G_LOG_LEVEL_ERROR;

Expand Down
2 changes: 1 addition & 1 deletion src/markup.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static bool markup_is_entity(const char *str)
return (cur == end);
} else {
const char *supported_tags[] = {"&amp;", "&lt;", "&gt;", "&quot;", "&apos;"};
for (int i = 0; i < sizeof(supported_tags)/sizeof(*supported_tags); i++) {
for (size_t i = 0; i < sizeof(supported_tags)/sizeof(*supported_tags); i++) {
if (g_str_has_prefix(str, supported_tags[i]))
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ char *notification_dmenu_string(struct notification *n)
void invoke_action(const char *action)
{
struct notification *invoked = NULL;
uint id;
gint id;

char *data_start, *data_comma, *data_end;

Expand Down Expand Up @@ -273,7 +273,8 @@ char *invoke_dmenu(const char *dmenu_input)
g_error_free(err);
} else {
size_t wlen = strlen(dmenu_input);
if (write(dunst_to_dmenu, dmenu_input, wlen) != wlen) {
ssize_t n = write(dunst_to_dmenu, dmenu_input, wlen);
if (n < 0 || (size_t)n != wlen) {
LOG_W("Cannot feed dmenu with input: %s", strerror(errno));
}
close(dunst_to_dmenu);
Expand Down Expand Up @@ -368,6 +369,8 @@ static gboolean context_menu_result_dispatch(gpointer user_data)

static gpointer context_menu_thread(gpointer data)
{
(void)data;

char *dmenu_input = NULL;
char *dmenu_output;

Expand Down
25 changes: 13 additions & 12 deletions src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ void notification_print(const struct notification *n)
printf("\ticon_id: '%s'\n", STR_NN(n->icon_id));
printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : "");
printf("\tcategory: %s\n", STR_NN(n->category));
printf("\ttimeout: %ld\n", n->timeout/1000);
printf("\tstart: %ld\n", n->start);
printf("\ttimestamp: %ld\n", n->timestamp);
printf("\ttimeout: %"G_GINT64_FORMAT"\n", n->timeout/1000);
printf("\tstart: %"G_GINT64_FORMAT"\n", n->start);
printf("\ttimestamp: %"G_GINT64_FORMAT"\n", n->timestamp);
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency));
printf("\ttransient: %d\n", n->transient);
printf("\tformatted: '%s'\n", STR_NN(n->msg));
Expand Down Expand Up @@ -148,8 +148,8 @@ void notification_run_script(struct notification *n)
// Set environment variables
gchar *n_id_str = g_strdup_printf("%i", n->id);
gchar *n_progress_str = g_strdup_printf("%i", n->progress);
gchar *n_timeout_str = g_strdup_printf("%li", n->timeout/1000);
gchar *n_timestamp_str = g_strdup_printf("%li", n->timestamp / 1000);
gchar *n_timeout_str = g_strdup_printf("%"G_GINT64_FORMAT, n->timeout/1000);
gchar *n_timestamp_str = g_strdup_printf("%"G_GINT64_FORMAT, n->timestamp / 1000);
safe_setenv("DUNST_APP_NAME", appname);
safe_setenv("DUNST_SUMMARY", summary);
safe_setenv("DUNST_BODY", body);
Expand Down Expand Up @@ -230,6 +230,8 @@ int notification_cmp(const struct notification *a, const struct notification *b)
/* see notification.h */
int notification_cmp_data(const void *va, const void *vb, void *data)
{
(void)data;

struct notification *a = (struct notification *) va;
struct notification *b = (struct notification *) vb;

Expand Down Expand Up @@ -725,15 +727,14 @@ void notification_update_text_to_render(struct notification *n)

char *new_buf;
if (hours > 0) {
new_buf =
g_strdup_printf("%s (%ldh %ldm %lds old)", buf, hours,
minutes, seconds);
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"h %"G_GINT64_FORMAT"m %"G_GINT64_FORMAT"s old)",
buf, hours, minutes, seconds);
} else if (minutes > 0) {
new_buf =
g_strdup_printf("%s (%ldm %lds old)", buf, minutes,
seconds);
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"m %"G_GINT64_FORMAT"s old)",
buf, minutes, seconds);
} else {
new_buf = g_strdup_printf("%s (%lds old)", buf, seconds);
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"s old)",
buf, seconds);
}

g_free(buf);
Expand Down
2 changes: 1 addition & 1 deletion src/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct notification_colors {

struct notification {
NotificationPrivate *priv;
int id;
gint id;
char *dbus_client;
bool dbus_valid;

Expand Down
4 changes: 2 additions & 2 deletions src/option_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int get_setting_id(const char *key, const char *section) {
if (!match_section) {
LOG_D("not matching section %s", section);
}
for (int i = 0; i < G_N_ELEMENTS(allowed_settings); i++) {
for (size_t i = 0; i < G_N_ELEMENTS(allowed_settings); i++) {
if (strcmp(allowed_settings[i].name, key) == 0) {
bool is_rule = allowed_settings[i].rule_offset > 0;

Expand Down Expand Up @@ -489,7 +489,7 @@ void set_defaults(void) {
LOG_D("Initializing settings");
settings = (struct settings) {0};

for (int i = 0; i < G_N_ELEMENTS(allowed_settings); i++) {
for (size_t i = 0; i < G_N_ELEMENTS(allowed_settings); i++) {
// FIXME Rule settings can only have a default if they have an
// working entry in the settings struct as well. Make an
// alternative way of setting defaults for rules.
Expand Down
Loading
Loading