[Spice-devel] [PATCH spicec windows 1/1] client/windows: fix SetClipboardViewer error handling rhbz#786554

Alon Levy alevy at redhat.com
Thu Mar 1 04:01:45 PST 2012


On Thu, Mar 01, 2012 at 01:10:51PM +0200, Arnon Gilboa wrote:
> MSDN says the following about SetClipboardViewer(): "If an error occurs or there
> are no other windows in the clipboard viewer chain, the return value is NULL".
> Seems like the buggy case was "no other windows in the clipboard viewer chain",
> which explains the 3rd party clipboard manager workaround detailed in the bug
> description.

But the fix below looks like it's dealing with the case there is an
already existing LastError that is not reset before the
SetClipboardViewer call, which you fix by adding a SetLastError(0), no?

> ---
>  client/windows/platform.cpp |    7 ++++---
>  1 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
> index 0f35a65..223be1d 100644
> --- a/client/windows/platform.cpp
> +++ b/client/windows/platform.cpp
> @@ -236,6 +236,7 @@ static void create_message_wind()
>  {
>      WNDCLASSEX wclass;
>      ATOM class_atom;
> +    DWORD err;
>  
>      const LPCWSTR class_name = L"spicec_platform_wclass";
>  
> @@ -259,9 +260,9 @@ static void create_message_wind()
>      if (!(platform_win = CreateWindow(class_name, L"", 0, 0, 0, 0, 0, NULL, NULL, instance, NULL))) {
>          THROW("create message window failed");
>      }
> -
> -    if (!(next_clipboard_viewer_win = SetClipboardViewer(platform_win)) && GetLastError()) {
> -        THROW("set clipboard viewer failed");
> +    SetLastError(0);
> +    if (!(next_clipboard_viewer_win = SetClipboardViewer(platform_win)) && (err = GetLastError())) {
> +        THROW("set clipboard viewer failed %u", err);
>      }
>      if (!(clipboard_event = CreateEvent(NULL, FALSE, FALSE, NULL))) {
>          THROW("create clipboard event failed");
> -- 
> 1.7.4.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list