On Tue, 23 Sep 2025 at 11:02:06 +0000, Pranav P wrote:
Instead of hard coding the values, this was what I had come up with.

diff --git a/src/core/linux/SDL_progressbar.c b/src/core/linux/SDL_progressbar.c
index ac0789b2d..8ec28eba7 100644
--- a/src/core/linux/SDL_progressbar.c
+++ b/src/core/linux/SDL_progressbar.c
@@ -120,8 +120,8 @@ bool DBUS_ApplyWindowProgress(SDL_VideoDevice *_this, 
SDL_Window *window)

    const char *progress_visible_str = "progress-visible";
    const char *progress_str = "progress";
-    int dbus_type_boolean_str = DBUS_TYPE_BOOLEAN;
-    int dbus_type_double_str = DBUS_TYPE_DOUBLE;
+    char dbus_type_boolean_str = DBUS_TYPE_BOOLEAN;
+    char dbus_type_double_str = DBUS_TYPE_DOUBLE;

This is not correct. In message_iter_open_container(), DBUS_TYPE_VARIANT
needs to be followed by a pointer to a nul-terminated string, but C does not guarantee that an initialized 'char' variable will be followed in memory by a zero byte. (Perhaps the stack layout used by practical s390x compilers does guarantee this, but C, in general, does not.)

To make this correct you would have to use

    char dbus_type_boolean_str[] = { DBUS_TYPE_BOOLEAN, '\0' };

but it's simpler to use string constants like "b", or equivalently DBUS_TYPE_BOOLEAN_AS_STRING.

The numeric values of DBUS_TYPE_BOOLEAN, DBUS_TYPE_DOUBLE, etc. are chosen to match mnemonic ASCII characters ('b' and 'd' in this case), so it is safe to hard-code them as strings (and the SDL_portaldialog module already does this). Their numeric values are part of the D-Bus Specification, <https://dbus.freedesktop.org/doc/dbus-specification.html>.

Does the change that I proposed work? I've attached it in the form of a patch for easier testing. I'm hoping to upload it to experimental soon, but I've encountered some trouble with my usual test game (openarena) crashing my GNOME session when started - which I *think* is a GNOME regression rather than an SDL bug, but I need to investigate that before uploading.

    smcv
>From 282d71e9ef476708a4e086fcabef61d8197442fc Mon Sep 17 00:00:00 2001
From: Simon McVittie <[email protected]>
Date: Tue, 23 Sep 2025 10:46:43 +0100
Subject: [PATCH] progress: Correct calls to dbus_message_iter_open_container
 with variants

As documented, the contained_signature is to be passed in as a
nul-terminated C string.

For basic types that are represented by a single character, on
little-endian platforms, putting the type in the least significant
byte of an int and casting its address to `char *` happens to result in
a valid string, because the int's in-memory representation looks like
`(char []){ 'b', 0, 0, 0 }`. However, on big-endian platforms, the int's
in-memory representation is `(char []){ 0, 0, 0, 'b' }` which is not
a valid type for a D-Bus variant to hold (it is interpreted as an empty
string, and variants are not allowed to be empty).

Instead, do this the straightforward way, with a mnemonic string and
no casts (in the same style used in `SDL_portaldialog`).

Fixes: 3f2226a9 "Add progress bar support for Linux"
Resolves: https://github.com/libsdl-org/SDL/issues/13953
Bug-Debian: https://bugs.debian.org/1115705
Signed-off-by: Simon McVittie <[email protected]>
---
 src/core/linux/SDL_progressbar.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/core/linux/SDL_progressbar.c b/src/core/linux/SDL_progressbar.c
index ac0789b2d..9f98e6acf 100644
--- a/src/core/linux/SDL_progressbar.c
+++ b/src/core/linux/SDL_progressbar.c
@@ -120,8 +120,6 @@ bool DBUS_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window *window)
 
     const char *progress_visible_str = "progress-visible";
     const char *progress_str = "progress";
-    int dbus_type_boolean_str = DBUS_TYPE_BOOLEAN;
-    int dbus_type_double_str = DBUS_TYPE_DOUBLE;
 
     const int progress_visible = ShouldShowProgress(window->progress_state);
     double progress = (double)window->progress_value;
@@ -134,14 +132,14 @@ bool DBUS_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window *window)
     // Set progress visible property
     dbus->message_iter_open_container(&props, DBUS_TYPE_DICT_ENTRY, NULL, &key_it);
     dbus->message_iter_append_basic(&key_it, DBUS_TYPE_STRING, &progress_visible_str); // Append progress-visible key data
-    dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, (const char *)&dbus_type_boolean_str, &value_it);
+    dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, "b", &value_it);
     dbus->message_iter_append_basic(&value_it, DBUS_TYPE_BOOLEAN, &progress_visible); // Append progress-visible value data
     dbus->message_iter_close_container(&key_it, &value_it);
     dbus->message_iter_close_container(&props, &key_it);
     // Set progress value property
     dbus->message_iter_open_container(&props, DBUS_TYPE_DICT_ENTRY, NULL, &key_it);
     dbus->message_iter_append_basic(&key_it, DBUS_TYPE_STRING, &progress_str); // Append progress key data
-    dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, (const char *)&dbus_type_double_str, &value_it);
+    dbus->message_iter_open_container(&key_it, DBUS_TYPE_VARIANT, "d", &value_it);
     dbus->message_iter_append_basic(&value_it, DBUS_TYPE_DOUBLE, &progress); // Append progress value data
     dbus->message_iter_close_container(&key_it, &value_it);
     dbus->message_iter_close_container(&props, &key_it);
-- 
2.51.0

Reply via email to