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

fix(usb): Fix -Wincompatible-pointer-types compiler error #2795

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/usb_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int get_report_cb(const struct device *dev, struct usb_setup_packet *setu
case HID_REPORT_TYPE_INPUT:
switch (setup->wValue & HID_GET_REPORT_ID_MASK) {
case ZMK_HID_REPORT_ID_KEYBOARD: {
*data = get_keyboard_report(len);
*data = get_keyboard_report((size_t *)len);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't actually fix the issue that the compiler is warning you about. It just says, "I know what I'm doing", so the compiler stops warning about it.

len is still a pointer to int32_t. Casting it to a pointer to size_t means that get_keyboard_report() is going to write a size_t to the memory that is actually an int32_t. On a platform such as native_posix_64 where size_t is uint64_t, it will write a 64-bit value to the given address, but the variable is only 32 bits, so it clobbers some memory after it.

Some safe alternatives:

  • Change get_keyboard_report() to also use an int32_t for its output parameter (requires also updating any other places that call the function to use int32_t as well).
  • Create a new size_t variable here, pass its address to get_keyboard_report(), then assign its value to len.

break;
}
case ZMK_HID_REPORT_ID_CONSUMER: {
Expand Down
Loading