diff --git a/0001-main.c-fix-build-against-gcc-14-Walloc-size.patch b/0001-main.c-fix-build-against-gcc-14-Walloc-size.patch new file mode 100644 index 0000000..f0c103e --- /dev/null +++ b/0001-main.c-fix-build-against-gcc-14-Walloc-size.patch @@ -0,0 +1,47 @@ +From 2b4446f550160b3e04ab65d5419c0a1f8a39558c Mon Sep 17 00:00:00 2001 +From: Sergei Trofimovich +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 +--- + 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 + diff --git a/swaybg.spec b/swaybg.spec index 5ca7aff..7948fb1 100644 --- a/swaybg.spec +++ b/swaybg.spec @@ -9,6 +9,8 @@ Source0: %{url}/releases/download/v%{version}/%{name}-%{version}.tar.gz Source1: %{url}/releases/download/v%{version}/%{name}-%{version}.tar.gz.sig Source2: https://keys.openpgp.org/vks/v1/by-fingerprint/34FF9526CFEF0E97A340E2E40FDE7BE0E88F5E48 +Patch: 0001-main.c-fix-build-against-gcc-14-Walloc-size.patch + # Swaybg was part of sway before sway 1.1 Conflicts: sway < 1.1