VirtualBox

Changeset 9123 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 26, 2008 1:35:06 PM (17 years ago)
Author:
vboxsync
Message:

Additions/x11: fixed a problem in the X11 clipboard code, whereby host to guest transfers of over 1K failed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/xclient/clipboard.cpp

    r8951 r9123  
    177177 * @returns VBox result code
    178178 * @param   u32Format The format of the data being requested
    179  * @retval  ppv       On success, this will point to a buffer to be freed with RTMemFree
    180  *                    containing the data read if pcb > 0.
    181  * @retval  pcb       On success, this contains the number of bytes of data returned
     179 * @retval  ppv       On success and if pcb > 0, this will point to a buffer
     180 *                    to be freed with RTMemFree containing the data read.
     181 * @retval  pcb       On success, this contains the number of bytes of data
     182 *                    returned
    182183 */
    183184static int vboxClipboardReadHostData(uint32_t u32Format, void **ppv, uint32_t *pcb)
    184185{
    185     int rc;
     186    int rc = VINF_SUCCESS;
    186187    uint32_t cb = 1024;
    187188    void *pv = RTMemAlloc(cb);
     189
     190    *ppv = 0;
    188191    LogFlowFunc(("u32Format=%u\n", u32Format));
    189192    if (RT_UNLIKELY(!pv))
    190     {
    191         LogFlowFunc(("rc=VERR_NO_MEMORY\n"));
    192         return VERR_NO_MEMORY;
    193     }
    194     rc = VbglR3ClipboardReadData(g_ctx.client, u32Format, pv, cb, pcb);
     193        rc = VERR_NO_MEMORY;
    195194    if (RT_SUCCESS(rc))
    196     {
     195        rc = VbglR3ClipboardReadData(g_ctx.client, u32Format, pv, cb, pcb);
     196    if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
    197197        *ppv = pv;
    198         return rc;
    199     }
    200     RTMemFree(pv);
     198    /* A return value of VINF_BUFFER_OVERFLOW tells us to try again with a
     199     * larger buffer.  The size of the buffer needed is placed in *pcb.
     200     * So we start all over again. */
    201201    if (rc == VINF_BUFFER_OVERFLOW)
    202202    {
    203         /* Supplied buffer of 1024 bytes was not big enough. Try again. */
    204203        cb = *pcb;
     204        RTMemFree(pv);
    205205        pv = RTMemAlloc(cb);
    206         rc = VbglR3ClipboardReadData(g_ctx.client, u32Format, pv, cb, pcb);
     206        if (RT_UNLIKELY(!pv))
     207            rc = VERR_NO_MEMORY;
    207208        if (RT_SUCCESS(rc))
    208         {
     209            rc = VbglR3ClipboardReadData(g_ctx.client, u32Format, pv, cb, pcb);
     210        if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
    209211            *ppv = pv;
    210             return rc;
    211         }
    212 
    213         RTMemFree(pv);
    214         *ppv = 0;
     212    }
     213    /* Catch other errors. This also catches the case in which the buffer was
     214     * too small a second time, possibly because the clipboard contents
     215     * changed half-way through the operation.  Since we can't say whether or
     216     * not this is actually an error, we just return size 0.
     217     */
     218    if (RT_FAILURE(rc) || (VINF_BUFFER_OVERFLOW == rc))
     219    {
    215220        *pcb = 0;
    216         if (rc == VINF_BUFFER_OVERFLOW)
    217         {
    218             /* The buffer was to small again.  Perhaps the clipboard contents changed half-way through
    219              * the operation.  Since I can't say whether or not this is actually an error, we will just
    220              * return size 0.
    221              */
    222             return VINF_SUCCESS;
    223         }
    224     }
    225     /* Other errors. */
    226     *ppv = 0;
    227     *pcb = 0;
     221        if (pv != NULL)
     222            RTMemFree(pv);
     223    }
     224    LogFlowFunc(("returning %Rrc\n", rc));
     225    if (RT_SUCCESS(rc))
     226        LogFlow(("    *pcb=%d\n", *pcb));
    228227    return rc;
    229228}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette