VirtualBox

Changeset 108813 in vbox for trunk/src


Ignore:
Timestamp:
Apr 1, 2025 3:16:47 PM (2 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168259
Message:

DnD: Added some more format checks and simplified DnDTransferListAppendPathsFromArray().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/DragAndDrop/DnDTransferList.cpp

    r106061 r108813  
    769769    AssertReturn(!(fFlags & ~DNDTRANSFERLIST_FLAGS_VALID_MASK), VERR_INVALID_FLAGS);
    770770
    771     int rc = VINF_SUCCESS;
    772 
    773771    if (!cPaths) /* Nothing to add? Bail out. */
    774772        return VINF_SUCCESS;
    775773
    776     char **papszPathsTmp = NULL;
    777 
    778     /* If URI data is being handed in, extract the paths first. */
    779     if (enmFmt == DNDTRANSFERLISTFMT_URI)
    780     {
    781         papszPathsTmp = (char **)RTMemAlloc(sizeof(char *) * cPaths);
    782         if (papszPathsTmp)
    783         {
     774    char **papszPathsConverted = NULL;
     775
     776    int rc = VINF_SUCCESS;
     777
     778    switch (enmFmt)
     779    {
     780        /* If URI data is being handed in, extract the paths first. */
     781        case DNDTRANSFERLISTFMT_URI:
     782        {
     783            papszPathsConverted = (char **)RTMemAllocZ(sizeof(char *) * cPaths);
     784            AssertPtrReturn(papszPathsConverted, VERR_NO_MEMORY);
    784785            for (size_t i = 0; i < cPaths; i++)
    785                 papszPathsTmp[i] = RTUriFilePath(papcszPaths[i]);
    786         }
    787         else
    788             rc = VERR_NO_MEMORY;
    789     }
    790 
    791     if (RT_FAILURE(rc))
    792         return rc;
     786            {
     787                papszPathsConverted[i] = RTUriFilePath(papcszPaths[i]);
     788                AssertPtrBreakStmt(papszPathsConverted[i], rc = VERR_INVALID_PARAMETER);
     789            }
     790
     791            papcszPaths = papszPathsConverted;
     792            break;
     793        }
     794
     795        case DNDTRANSFERLISTFMT_NATIVE:
     796            /* Use original paths handed-in. */
     797            break;
     798
     799        default:
     800            AssertFailedStmt(rc = VERR_NOT_SUPPORTED);
     801            break;
     802    }
    793803
    794804    /* If we don't have a root path set, try to find the common path of all handed-in paths. */
    795     if (!pList->pszPathRootAbs)
    796     {
    797         /* Can we work on the unmodified, handed-in data or do we need to use our temporary paths? */
    798         const char * const *papszPathTmp = enmFmt == DNDTRANSFERLISTFMT_NATIVE
    799                                          ? papcszPaths : papszPathsTmp;
    800 
     805    if (   RT_SUCCESS(rc)
     806        && !pList->pszPathRootAbs)
     807    {
    801808        size_t cchRootPath = 0; /* Length of root path in chars. */
    802809        if (cPaths > 1)
    803         {
    804             cchRootPath = RTPathFindCommon(cPaths, papszPathTmp);
    805         }
     810            cchRootPath = RTPathFindCommon(cPaths, papcszPaths);
    806811        else
    807             cchRootPath = RTPathParentLength(papszPathTmp[0]);
    808 
     812            cchRootPath = RTPathParentLength(papcszPaths[0]);
    809813        if (cchRootPath)
    810814        {
    811815            /* Just use the first path in the array as the reference. */
    812             char *pszRootPath = RTStrDupN(papszPathTmp[0], cchRootPath);
     816            char *pszRootPath = RTStrDupN(papcszPaths[0], cchRootPath);
    813817            if (pszRootPath)
    814818            {
     
    826830    {
    827831        /*
    828          * Add all paths to the list.
     832         * Add all paths (as native paths) to the list.
    829833         */
    830834        for (size_t i = 0; i < cPaths; i++)
    831835        {
    832             const char *pcszPath = enmFmt == DNDTRANSFERLISTFMT_NATIVE
    833                                  ? papcszPaths[i] : papszPathsTmp[i];
    834             rc = DnDTransferListAppendPath(pList, DNDTRANSFERLISTFMT_NATIVE, pcszPath, fFlags);
     836            rc = DnDTransferListAppendPath(pList, DNDTRANSFERLISTFMT_NATIVE, papcszPaths[i], fFlags);
    835837            if (RT_FAILURE(rc))
    836838            {
    837839                LogRel(("DnD: Adding path '%s' (format %#x, root '%s') to transfer list failed with %Rrc\n",
    838                         pcszPath, enmFmt, pList->pszPathRootAbs ? pList->pszPathRootAbs : "<None>", rc));
     840                        papcszPaths[i], enmFmt, pList->pszPathRootAbs ? pList->pszPathRootAbs : "<None>", rc));
    839841                break;
    840842            }
     
    842844    }
    843845
    844     if (papszPathsTmp)
     846    if (papszPathsConverted)
    845847    {
    846848        for (size_t i = 0; i < cPaths; i++)
    847             RTStrFree(papszPathsTmp[i]);
    848         RTMemFree(papszPathsTmp);
     849            RTStrFree(papszPathsConverted[i]);
     850        RTMemFree(papszPathsConverted);
    849851    }
    850852
Note: See TracChangeset for help on using the changeset viewer.

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