Skip to content

Added unsafe line in clipboard_windows.c.v - #20733

Merged
spytheman merged 1 commit into
vlang:masterfrom
max00217:master
Feb 5, 2024
Merged

spytheman merged 1 commit into
vlang:masterfrom
max00217:master

Conversation

@max00217

@max00217 max00217 commented Feb 5, 2024

Copy link
Copy Markdown
Contributor

clipboard: Add unsafe line for windows

This PR modifies the WndClassEx struct initialization to handle lpsz_menu_name and h_icon_sm in an unsafe block. This is necessary because V language requires explicit unsafe block for operations that could lead to undefined behaviors.

Before:

// v/vlib/clipboard/clipboard_windows.c.v
.
.
.
wndclass := WndClassEx{
    cb_size: sizeof(WndClassEx)
    lpfn_wnd_proc: voidptr(&C.DefWindowProc)
    lpsz_class_name: class_name.to_wide()
    lpsz_menu_name: 0
    h_icon_sm: 0
}

After:

// v/vlib/clipboard/clipboard_windows.c.v
.
.
.
wndclass := WndClassEx{
    cb_size: sizeof(WndClassEx)
    lpfn_wnd_proc: voidptr(&C.DefWindowProc)
    lpsz_class_name: class_name.to_wide()
    lpsz_menu_name: unsafe { 0 }
    h_icon_sm: unsafe { 0 }
}

Fix this notice

C:/Program Files/v/vlib/clipboard/clipboard_windows.c.v:96:3: notice: assigning `0` to a reference field is only allowed in `unsafe` blocks
   94 |         lpfn_wnd_proc: voidptr(&C.DefWindowProc)
   95 |         lpsz_class_name: class_name.to_wide()
   96 |         lpsz_menu_name: 0
      |         ~~~~~~~~~~~~~~~~~
   97 |         h_icon_sm: 0
   98 |     }
C:/Program Files/v/vlib/clipboard/clipboard_windows.c.v:97:3: notice: assigning `0` to a reference field is only allowed in `unsafe` blocks
   95 |         lpsz_class_name: class_name.to_wide()
   96 |         lpsz_menu_name: 0
   97 |         h_icon_sm: 0
      |         ~~~~~~~~~~~~
   98 |     }
   99 |     if C.RegisterClassEx(voidptr(&wndclass)) == 0

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@spytheman
spytheman merged commit a374d25 into vlang:master Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants