Repository: libsdl-org/SDL
File: src/tray/windows/SDL_tray.c (C)

Code before:
    tray->left_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, NULL);
    tray->right_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, NULL);
    tray->middle_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, NULL);
    tray->double_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER, NULL);

    tray->menu = NULL;
    if (!SDL_RegisterTrayClass(TEXT("SDL_TRAY"))) {
        SDL_SetError("Failed to register SDL_TRAY window class");
        SDL_free(tray);
        return NULL;
    }
    tray->hwnd = CreateWindowEx(0, TEXT("SDL_TRAY"), NULL, WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);

    WIN_UpdateDarkModeForHWND(tray->hwnd);

    SDL_zero(tray->nid);
    tray->nid.cbSize = sizeof(NOTIFYICONDATAW);
    tray->nid.hWnd = tray->hwnd;
    tray->nid.uID = (UINT) get_next_id();
    tray->nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP;
    tray->nid.uCallbackMessage = WM_TRAYICON;
    tray->nid.uVersion = NOTIFYICON_VERSION_4;
    if (tooltip) {
        wchar_t *tooltipw = WIN_UTF8ToStringW(tooltip);
        SDL_wcslcpy(tray->nid.szTip, tooltipw, sizeof(tray->nid.szTip) / sizeof(*tray->nid.szTip));
        SDL_free(tooltipw);
    }

    if (icon) {
        tray->nid.hIcon = WIN_CreateIconFromSurface(icon);

        if (!tray->nid.hIcon) {
            tray->nid.hIcon = load_default_icon();
        }

        tray->icon = tray->nid.hIcon;
    } else {
        tray->nid.hIcon = load_default_icon();
        tray->icon = tray->nid.hIcon;
    }

    Shell_NotifyIconW(NIM_ADD, &tray->nid);
    Shell_NotifyIconW(NIM_SETVERSION, &tray->nid);

    SetWindowLongPtr(tray->hwnd, GWLP_USERDATA, (LONG_PTR) tray);

    SDL_RegisterTray(tray);

    return tray;
}

Review comment (suggestion):
```suggestion
        if (tooltipw) {
            SDL_wcslcpy(tray->nid.szTip, tooltipw, sizeof(tray->nid.szTip) / sizeof(*tray->nid.szTip));
        }
```

Code after:
    tray->left_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_LEFTCLICK_CALLBACK_POINTER, NULL);
    tray->right_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_RIGHTCLICK_CALLBACK_POINTER, NULL);
    tray->middle_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_MIDDLECLICK_CALLBACK_POINTER, NULL);
    tray->double_click_callback = (SDL_TrayClickCallback)SDL_GetPointerProperty(props, SDL_PROP_TRAY_CREATE_DOUBLECLICK_CALLBACK_POINTER, NULL);

    tray->menu = NULL;
    if (!SDL_RegisterTrayClass(TEXT("SDL_TRAY"))) {
        SDL_SetError("Failed to register SDL_TRAY window class");
        SDL_free(tray);
        return NULL;
    }
    tray->hwnd = CreateWindowEx(0, TEXT("SDL_TRAY"), NULL, WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, NULL, NULL);

    WIN_UpdateDarkModeForHWND(tray->hwnd);

    SDL_zero(tray->nid);
    tray->nid.cbSize = sizeof(NOTIFYICONDATAW);
    tray->nid.hWnd = tray->hwnd;
    tray->nid.uID = (UINT) get_next_id();
    tray->nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_SHOWTIP;
    tray->nid.uCallbackMessage = WM_TRAYICON;
    tray->nid.uVersion = NOTIFYICON_VERSION_4;
    if (tooltip) {
        wchar_t *tooltipw = WIN_UTF8ToStringW(tooltip);
        if(tooltipw) {
            SDL_wcslcpy(tray->nid.szTip, tooltipw, sizeof(tray->nid.szTip) / sizeof(*tray->nid.szTip));
            SDL_free(tooltipw);
        }
    }

    if (icon) {
        tray->nid.hIcon = WIN_CreateIconFromSurface(icon);

        if (!tray->nid.hIcon) {
            tray->nid.hIcon = load_default_icon();
        }

        tray->icon = tray->nid.hIcon;
    } else {
        tray->nid.hIcon = load_default_icon();
        tray->icon = tray->nid.hIcon;
    }

    Shell_NotifyIconW(NIM_ADD, &tray->nid);
    Shell_NotifyIconW(NIM_SETVERSION, &tray->nid);

    SetWindowLongPtr(tray->hwnd, GWLP_USERDATA, (LONG_PTR) tray);

    SDL_RegisterTray(tray);