backend-rdp/rdpclip: Avoid printing negative index

As clipboard_find_supported_format_by_mime_type() can return -1 if it
can't find out an index avoid trying to print outside of the array.

Fixes the following warnings triggered when enabling FORTIFY_SOURCE
combined with optimizations (-O)

../libweston/backend-rdp/rdpclip.c:1114:17: error: array subscript -1 is below array bounds of ‘uint32_t[5]’ {aka ‘unsigned int[5]’} [-Werror=array-bounds]
 1114 |                 weston_log("RDP %s (%p:%s) specified format \"%s\" index:%d formatId:%d is not supported by client\n",
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1115 |                            __func__, source, clipboard_data_source_state_to_string(source),
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1116 |                            mime_type, index, source->client_format_id_table[index]);
      |                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../libweston/backend-rdp/rdpclip.c:131:18: note: while referencing ‘client_format_id_table’
  131 |         uint32_t client_format_id_table[RDP_NUM_CLIPBOARD_FORMATS];

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2022-09-21 10:54:09 +03:00 committed by Pekka Paalanen
parent 1cb46994e3
commit 9455ad7c7c

View File

@ -1111,9 +1111,9 @@ clipboard_data_source_send(struct weston_data_source *base,
}
} else {
source->state = RDP_CLIPBOARD_SOURCE_FAILED;
weston_log("RDP %s (%p:%s) specified format \"%s\" index:%d formatId:%d is not supported by client\n",
weston_log("RDP %s (%p:%s) specified format \"%s\" index:%d is not supported by client\n",
__func__, source, clipboard_data_source_state_to_string(source),
mime_type, index, source->client_format_id_table[index]);
mime_type, index);
goto error_return_close_fd;
}