diff mbox series

[v4,01/18] ui: avoid compiler warnings from unused clipboard info variable

Message ID 20211124130150.268230-2-berrange@redhat.com
State New
Headers show
Series tests/docker: start using libvirt-ci's "lcitool" for dockerfiles | expand

Commit Message

Daniel P. Berrangé Nov. 24, 2021, 1:01 p.m. UTC
With latest clang 13.0.0 we get

../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]
    g_autoptr(QemuClipboardInfo) old = NULL;
                                 ^

The compiler can't tell that we only declared this variable in
order to get the side effect of free'ing it when out of scope.

This pattern is a little dubious for a use of g_autoptr, so
rewrite the code to avoid it.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 ui/clipboard.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé Nov. 24, 2021, 1:33 p.m. UTC | #1
On 11/24/21 14:01, Daniel P. Berrangé wrote:
> With latest clang 13.0.0 we get
> 
> ../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]
>     g_autoptr(QemuClipboardInfo) old = NULL;
>                                  ^
> 
> The compiler can't tell that we only declared this variable in
> order to get the side effect of free'ing it when out of scope.
> 
> This pattern is a little dubious for a use of g_autoptr, so
> rewrite the code to avoid it.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  ui/clipboard.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Philippe Mathieu-Daudé Dec. 15, 2021, 10:22 a.m. UTC | #2
On 11/24/21 14:33, Philippe Mathieu-Daudé wrote:
> On 11/24/21 14:01, Daniel P. Berrangé wrote:
>> With latest clang 13.0.0 we get
>>
>> ../ui/clipboard.c:47:34: error: variable 'old' set but not used [-Werror,-Wunused-but-set-variable]
>>     g_autoptr(QemuClipboardInfo) old = NULL;
>>                                  ^
>>
>> The compiler can't tell that we only declared this variable in
>> order to get the side effect of free'ing it when out of scope.
>>
>> This pattern is a little dubious for a use of g_autoptr, so
>> rewrite the code to avoid it.
>>
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>> ---
>>  ui/clipboard.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 

Could we get this patch directly applied as a buildfix?
diff mbox series

Patch

diff --git a/ui/clipboard.c b/ui/clipboard.c
index d7b008d62a..7672058e84 100644
--- a/ui/clipboard.c
+++ b/ui/clipboard.c
@@ -44,12 +44,11 @@  void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
 
 void qemu_clipboard_update(QemuClipboardInfo *info)
 {
-    g_autoptr(QemuClipboardInfo) old = NULL;
     assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
 
     notifier_list_notify(&clipboard_notifiers, info);
 
-    old = cbinfo[info->selection];
+    qemu_clipboard_info_unref(cbinfo[info->selection]);
     cbinfo[info->selection] = qemu_clipboard_info_ref(info);
 }