Fixed SDL_strncmp() logic in portal dialog code

Also removed redundant calls to SDL_strlen()

Fixes https://github.com/libsdl-org/SDL/issues/9899
This commit is contained in:
Sam Lantinga
2024-05-27 07:46:58 -07:00
parent df25e4022d
commit a5b0041b4a

View File

@@ -226,6 +226,8 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
while (dbus->message_iter_get_arg_type(&uri_entry) == DBUS_TYPE_STRING)
{
const char *prefix = "file://";
const int prefix_len = 7;
const char *uri = NULL;
if (current >= length - 1) {
@@ -241,8 +243,8 @@ static DBusHandlerResult DBus_MessageFilter(DBusConnection *conn, DBusMessage *m
/* https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.FileChooser.html */
/* Returned paths will always start with 'file://'; truncate it */
if (SDL_strncmp(uri, "file://", SDL_strlen("file://"))) {
path[current] = uri + SDL_strlen("file://");
if (SDL_strncmp(uri, prefix, prefix_len) == 0) {
path[current] = uri + prefix_len;
} else if (SDL_strstr(uri, "://")) {
SDL_SetError("Portal dialogs: Unsupported protocol: %s", uri);
signal_data->callback(signal_data->userdata, NULL, -1);