Blob Blame History Raw
From 2b4446f550160b3e04ab65d5419c0a1f8a39558c Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <slyich@gmail.com>
Date: Thu, 2 Nov 2023 20:04:24 +0000
Subject: [PATCH] main.c: fix build against gcc-14 (-Walloc-size)

`gcc-14` added a new `-Walloc-size` warning that makes sure that size of
an individual element matches size of a pointed type:

        https://gcc.gnu.org/PR71219

`swaybg` triggers it on `calloc()` calls where member size is used as
`1` (instead of member count):

    ../main.c:492:32: error: allocation of insufficient size '1' for type 'struct swaybg_output_config' with size '48' [-Werror=alloc-size]
      492 |                         config = calloc(sizeof(struct swaybg_output_config), 1);
          |                                ^

Signed-off-by: rpm-build <rpm-build>
---
 main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/main.c b/main.c
index dce5b5a..211a874 100644
--- a/main.c
+++ b/main.c
@@ -455,7 +455,7 @@ static void parse_command_line(int argc, char **argv,
 		"Background Modes:\n"
 		"  stretch, fit, fill, center, tile, or solid_color\n";
 
-	struct swaybg_output_config *config = calloc(sizeof(struct swaybg_output_config), 1);
+	struct swaybg_output_config *config = calloc(1, sizeof(struct swaybg_output_config));
 	config->output = strdup("*");
 	config->mode = BACKGROUND_MODE_INVALID;
 	wl_list_init(&config->link); // init for safe removal
@@ -489,7 +489,7 @@ static void parse_command_line(int argc, char **argv,
 				// Empty config or merged on top of an existing one
 				destroy_swaybg_output_config(config);
 			}
-			config = calloc(sizeof(struct swaybg_output_config), 1);
+			config = calloc(1, sizeof(struct swaybg_output_config));
 			config->output = strdup(optarg);
 			config->mode = BACKGROUND_MODE_INVALID;
 			wl_list_init(&config->link);  // init for safe removal
-- 
2.43.0