Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unsafe line in clipboard_windows.c.v #20733

Merged
merged 1 commit into from
Feb 5, 2024
Merged

Conversation

max00217
Copy link
Contributor

@max00217 max00217 commented Feb 5, 2024

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

Copy link
Member

@spytheman spytheman left a comment

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
42 checks passed
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.

None yet

2 participants