From 715eb67cd8cc80dd7e828624493e0c6edf936d75 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Wed, 21 Sep 2022 10:54:09 +0300 Subject: [PATCH] backend-rdp/rdpclip: Avoid printing negative index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 9455ad7c7c07fdb8218330f449c97be73f695742) --- libweston/backend-rdp/rdpclip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libweston/backend-rdp/rdpclip.c b/libweston/backend-rdp/rdpclip.c index f92bf7a0..e08f4ca2 100644 --- a/libweston/backend-rdp/rdpclip.c +++ b/libweston/backend-rdp/rdpclip.c @@ -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; }