Skip to content

Commit 8010c7e

Browse files
authored
Merge pull request #1424 from bynect/fmting
Fix some warnings (gint formatting, size_t/int mix, etc)
2 parents b7abe8f + c3e648b commit 8010c7e

24 files changed

+199
-154
lines changed

src/dbus.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ void dbus_cb_fdn_methods(GDBusConnection *connection,
169169
GDBusMethodInvocation *invocation,
170170
gpointer user_data)
171171
{
172-
173172
struct dbus_method *m = bsearch(method_name,
174173
methods_fdn,
175174
G_N_ELEMENTS(methods_fdn),
@@ -225,7 +224,6 @@ void dbus_cb_dunst_methods(GDBusConnection *connection,
225224
GDBusMethodInvocation *invocation,
226225
gpointer user_data)
227226
{
228-
229227
struct dbus_method *m = bsearch(method_name,
230228
methods_dunst,
231229
G_N_ELEMENTS(methods_dunst),
@@ -236,8 +234,7 @@ void dbus_cb_dunst_methods(GDBusConnection *connection,
236234
m->method(connection, sender, parameters, invocation);
237235
} else {
238236
LOG_M("Unknown method name: '%s' (sender: '%s').",
239-
method_name,
240-
sender);
237+
method_name, sender);
241238
}
242239
}
243240

@@ -458,7 +455,7 @@ static void gradient_entry(const struct gradient *grad, GVariantDict *dict, cons
458455
}
459456

460457
char **strv = g_malloc((grad->length + 1) * sizeof(char *));
461-
for (int i = 0; i < grad->length; i++) {
458+
for (size_t i = 0; i < grad->length; i++) {
462459
char buf[10];
463460
if (color_to_string(grad->colors[i], buf))
464461
strv[i] = g_strdup(buf);
@@ -677,7 +674,7 @@ static void dbus_cb_GetCapabilities(
677674
g_variant_builder_add(builder, "s", "body-hyperlinks");
678675
g_variant_builder_add(builder, "s", "icon-static");
679676

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

683680
// Since markup isn't a global variable anymore, look it up in the
@@ -769,7 +766,7 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
769766
*
770767
* Only accept to first one we find.
771768
*/
772-
for (int i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i) {
769+
for (size_t i = 0; i < sizeof(stack_tag_hints)/sizeof(*stack_tag_hints); ++i) {
773770
if ((dict_value = g_variant_lookup_value(hints, stack_tag_hints[i], G_VARIANT_TYPE_STRING))) {
774771
n->stack_tag = g_variant_dup_string(dict_value, NULL);
775772
g_variant_unref(dict_value);
@@ -870,7 +867,7 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
870867
size_t length = g_strv_length(cols);
871868
struct gradient *grad = gradient_alloc(length);
872869

873-
for (int i = 0; i < length; i++) {
870+
for (size_t i = 0; i < length; i++) {
874871
if (!string_parse_color(cols[i], &grad->colors[i])) {
875872
g_free(grad);
876873
goto end;
@@ -911,7 +908,6 @@ static struct notification *dbus_message_to_notification(const gchar *sender, GV
911908

912909
void signal_length_propertieschanged(void)
913910
{
914-
915911
static unsigned int last_displayed = 0;
916912
static unsigned int last_history = 0;
917913
static unsigned int last_waiting = 0;
@@ -1215,7 +1211,7 @@ gboolean dbus_cb_dunst_Properties_Set(GDBusConnection *connection,
12151211

12161212

12171213
static const GDBusInterfaceVTable interface_vtable_fdn = {
1218-
dbus_cb_fdn_methods
1214+
dbus_cb_fdn_methods,
12191215
};
12201216

12211217
static const GDBusInterfaceVTable interface_vtable_dunst = {

src/draw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void gradient_pattern(struct gradient *grad)
110110
grad->colors[0].a);
111111
} else {
112112
grad->pattern = cairo_pattern_create_linear(0, 0, 1, 0);
113-
for (int i = 0; i < grad->length; i++) {
113+
for (size_t i = 0; i < grad->length; i++) {
114114
double offset = i / (double)(grad->length - 1);
115115
cairo_pattern_add_color_stop_rgba(grad->pattern,
116116
offset,
@@ -129,7 +129,7 @@ char *gradient_to_string(const struct gradient *grad)
129129
int max = grad->length * 11 + 1;
130130
char *buf = g_malloc(max);
131131

132-
for (int i = 0, j = 0; i < grad->length; i++) {
132+
for (size_t i = 0, j = 0; i < grad->length; i++) {
133133
j += g_snprintf(buf + j, max - j, "#%02x%02x%02x%02x",
134134
(int)(grad->colors[i].r * 255),
135135
(int)(grad->colors[i].g * 255),

src/dunst.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static gboolean run(void *data)
164164
gint64 sleep = timeout_at - now;
165165
sleep = MAX(sleep, 1000); // Sleep at least 1ms
166166

167-
LOG_D("Sleeping for %li ms", sleep/1000);
167+
LOG_D("Sleeping for %"G_GINT64_FORMAT" ms", sleep/1000);
168168

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

180180
gboolean pause_signal(gpointer data)
181181
{
182+
(void)data;
183+
182184
dunst_status_int(S_PAUSE_LEVEL, MAX_PAUSE_LEVEL);
183185
wake_up();
184186

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

188190
gboolean unpause_signal(gpointer data)
189191
{
192+
(void)data;
193+
190194
dunst_status_int(S_PAUSE_LEVEL, 0);
191195
wake_up();
192196

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

196200
gboolean quit_signal(gpointer data)
197201
{
202+
(void)data;
198203
g_main_loop_quit(mainloop);
199204

200205
return G_SOURCE_CONTINUE;

src/icon-lookup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void get_theme_path(void) {
168168

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

182-
for (int i = 0; i < theme_path->len; i++) {
182+
for (size_t i = 0; i < theme_path->len; i++) {
183183
int theme_index = load_icon_theme_from_dir(theme_path->pdata[i], name);
184184
if (theme_index != -1)
185185
return theme_index;

src/icon.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ char *get_path_from_icon_name(const char *iconname, int size)
268268
return path;
269269
}
270270

271+
static void icon_destroy(guchar *pixels, gpointer data)
272+
{
273+
(void)data;
274+
g_free(pixels);
275+
}
276+
271277
GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int min_size, int max_size)
272278
{
273279
ASSERT_OR_RET(data, NULL);
@@ -351,7 +357,7 @@ GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int mi
351357
width,
352358
height,
353359
rowstride,
354-
(GdkPixbufDestroyNotify) g_free,
360+
icon_destroy,
355361
data_pb);
356362
if (!pixbuf) {
357363
/* Dear user, I'm sorry, I'd like to give you a more specific

src/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static void dunst_log_handler(
7474
const gchar *message,
7575
gpointer testing)
7676
{
77+
(void)log_domain;
78+
7779
if (testing)
7880
log_level = G_LOG_LEVEL_ERROR;
7981

src/markup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static bool markup_is_entity(const char *str)
273273
return (cur == end);
274274
} else {
275275
const char *supported_tags[] = {"&amp;", "&lt;", "&gt;", "&quot;", "&apos;"};
276-
for (int i = 0; i < sizeof(supported_tags)/sizeof(*supported_tags); i++) {
276+
for (size_t i = 0; i < sizeof(supported_tags)/sizeof(*supported_tags); i++) {
277277
if (g_str_has_prefix(str, supported_tags[i]))
278278
return true;
279279
}

src/menu.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ char *notification_dmenu_string(struct notification *n)
169169
void invoke_action(const char *action)
170170
{
171171
struct notification *invoked = NULL;
172-
uint id;
172+
gint id;
173173

174174
char *data_start, *data_comma, *data_end;
175175

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

369370
static gpointer context_menu_thread(gpointer data)
370371
{
372+
(void)data;
373+
371374
char *dmenu_input = NULL;
372375
char *dmenu_output;
373376

src/notification.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ void notification_print(const struct notification *n)
6161
printf("\ticon_id: '%s'\n", STR_NN(n->icon_id));
6262
printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : "");
6363
printf("\tcategory: %s\n", STR_NN(n->category));
64-
printf("\ttimeout: %ld\n", n->timeout/1000);
65-
printf("\tstart: %ld\n", n->start);
66-
printf("\ttimestamp: %ld\n", n->timestamp);
64+
printf("\ttimeout: %"G_GINT64_FORMAT"\n", n->timeout/1000);
65+
printf("\tstart: %"G_GINT64_FORMAT"\n", n->start);
66+
printf("\ttimestamp: %"G_GINT64_FORMAT"\n", n->timestamp);
6767
printf("\turgency: %s\n", notification_urgency_to_string(n->urgency));
6868
printf("\ttransient: %d\n", n->transient);
6969
printf("\tformatted: '%s'\n", STR_NN(n->msg));
@@ -148,8 +148,8 @@ void notification_run_script(struct notification *n)
148148
// Set environment variables
149149
gchar *n_id_str = g_strdup_printf("%i", n->id);
150150
gchar *n_progress_str = g_strdup_printf("%i", n->progress);
151-
gchar *n_timeout_str = g_strdup_printf("%li", n->timeout/1000);
152-
gchar *n_timestamp_str = g_strdup_printf("%li", n->timestamp / 1000);
151+
gchar *n_timeout_str = g_strdup_printf("%"G_GINT64_FORMAT, n->timeout/1000);
152+
gchar *n_timestamp_str = g_strdup_printf("%"G_GINT64_FORMAT, n->timestamp / 1000);
153153
safe_setenv("DUNST_APP_NAME", appname);
154154
safe_setenv("DUNST_SUMMARY", summary);
155155
safe_setenv("DUNST_BODY", body);
@@ -230,6 +230,8 @@ int notification_cmp(const struct notification *a, const struct notification *b)
230230
/* see notification.h */
231231
int notification_cmp_data(const void *va, const void *vb, void *data)
232232
{
233+
(void)data;
234+
233235
struct notification *a = (struct notification *) va;
234236
struct notification *b = (struct notification *) vb;
235237

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

726728
char *new_buf;
727729
if (hours > 0) {
728-
new_buf =
729-
g_strdup_printf("%s (%ldh %ldm %lds old)", buf, hours,
730-
minutes, seconds);
730+
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"h %"G_GINT64_FORMAT"m %"G_GINT64_FORMAT"s old)",
731+
buf, hours, minutes, seconds);
731732
} else if (minutes > 0) {
732-
new_buf =
733-
g_strdup_printf("%s (%ldm %lds old)", buf, minutes,
734-
seconds);
733+
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"m %"G_GINT64_FORMAT"s old)",
734+
buf, minutes, seconds);
735735
} else {
736-
new_buf = g_strdup_printf("%s (%lds old)", buf, seconds);
736+
new_buf = g_strdup_printf("%s (%"G_GINT64_FORMAT"s old)",
737+
buf, seconds);
737738
}
738739

739740
g_free(buf);

src/notification.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct notification_colors {
4747

4848
struct notification {
4949
NotificationPrivate *priv;
50-
int id;
50+
gint id;
5151
char *dbus_client;
5252
bool dbus_valid;
5353

0 commit comments

Comments
 (0)