VirtualBox

Ignore:
Timestamp:
Oct 10, 2019 10:23:32 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133859
Message:

IPRT/RTPathParseSimple: Root handling fixes. bugref:9586 . ..\..\..\include\iprt\

Location:
trunk/src/VBox/Runtime/common/path
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/path/RTPathParse.cpp.h

    r78048 r81203  
    205205                    fProps |= RTPATH_PROP_FILENAME;
    206206
    207                     /* look for an ? */
     207                    /* Look for a suffix: */
    208208                    uint32_t offSuffix = offStart + cchComp;
    209                     while (offSuffix-- > offStart)
     209                    while (--offSuffix > offStart)
    210210                        if (pszPath[offSuffix] == '.')
    211211                        {
    212212                            uint32_t cchSuffix = offStart + cchComp - offSuffix;
    213                             if (cchSuffix > 1 && offStart != offSuffix)
     213                            if (cchSuffix > 1)
    214214                            {
    215215                                pParsed->cchSuffix = cchSuffix;
  • trunk/src/VBox/Runtime/common/path/RTPathParseSimple.cpp

    r76553 r81203  
    3232#include <iprt/path.h>
    3333
     34#include <iprt/assert.h>
     35#include <iprt/ctype.h>
     36
    3437
    3538/**
     
    5356RTDECL(size_t) RTPathParseSimple(const char *pszPath, size_t *pcchDir, ssize_t *poffName, ssize_t *poffSuff)
    5457{
    55     const char *psz = pszPath;
    56     ssize_t     offRoot = 0;
    57     const char *pszName = pszPath;
     58    /*
     59     * First deal with the root as it is always more fun that you'd think.
     60     */
     61    const char *psz     = pszPath;
     62    size_t      cchRoot = 0;
     63
     64#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     65    if (RT_C_IS_ALPHA(*psz) && RTPATH_IS_VOLSEP(psz[1]))
     66    {
     67        /* Volume specifier. */
     68        cchRoot = 2;
     69        psz    += 2;
     70    }
     71    else if (RTPATH_IS_SLASH(*psz) && RTPATH_IS_SLASH(psz[1]))
     72    {
     73        /* UNC - there are exactly two prefix slashes followed by a namespace
     74           or computer name, which can be empty on windows.  */
     75        cchRoot = 2;
     76        psz += 2;
     77        while (!RTPATH_IS_SLASH(*psz) && *psz)
     78        {
     79            cchRoot++;
     80            psz++;
     81        }
     82    }
     83#endif
     84    while (RTPATH_IS_SLASH(*psz))
     85    {
     86        cchRoot++;
     87        psz++;
     88    }
     89
     90    /*
     91     * Do the remainder.
     92     */
     93    const char *pszName = psz;
    5894    const char *pszLastDot = NULL;
    59 
    6095    for (;; psz++)
    6196    {
    6297        switch (*psz)
    6398        {
     99            default:
     100                break;
     101
    64102            /* handle separators. */
    65103#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    66             case ':':
    67                 pszName = psz + 1;
    68                 offRoot = pszName - psz;
    69                 break;
    70 
    71104            case '\\':
    72105#endif
    73106            case '/':
    74107                pszName = psz + 1;
     108                pszLastDot = NULL;
    75109                break;
    76110
     
    91125                {
    92126                    ssize_t offSuff = -1;
    93                     if (pszLastDot)
     127                    if (   pszLastDot
     128                        && pszLastDot != pszName
     129                        && pszLastDot[1] != '\0')
    94130                    {
    95131                        offSuff = pszLastDot - pszPath;
    96                         if (offSuff <= offName)
    97                             offSuff = -1;
     132                        Assert(offSuff > offName);
    98133                    }
    99134                    *poffSuff = offSuff;
     
    102137                if (pcchDir)
    103138                {
    104                     ssize_t off = offName - 1;
    105                     while (off >= offRoot && RTPATH_IS_SLASH(pszPath[off]))
    106                         off--;
    107                     *pcchDir = RT_MAX(off, offRoot) + 1;
     139                    size_t cch = offName < 0 ? psz - pszPath : offName - 1 < (ssize_t)cchRoot ? cchRoot : offName - 1;
     140                    while (cch > cchRoot && RTPATH_IS_SLASH(pszPath[cch - 1]))
     141                        cch--;
     142                    *pcchDir = cch;
    108143                }
    109144
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