VirtualBox

Changeset 34240 in vbox


Ignore:
Timestamp:
Nov 22, 2010 2:24:49 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67988
Message:

CFGMR3QueryStringAllocDef: Deal with pszDef = NULL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/CFGM.cpp

    r34186 r34240  
    26552655 * @param   ppszString      Where to store the string pointer. Not set on failure.
    26562656 *                          Free this using MMR3HeapFree().
     2657 * @param   pszDef          The default return value.  This can be NULL.
    26572658 */
    26582659VMMR3DECL(int) CFGMR3QueryStringAllocDef(PCFGMNODE pNode, const char *pszName, char **ppszString, const char *pszDef)
    26592660{
    2660     size_t cbString;
    2661     int rc = CFGMR3QuerySize(pNode, pszName, &cbString);
    2662     if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    2663     {
    2664         cbString = strlen(pszDef) + 1;
    2665         rc = VINF_SUCCESS;
    2666     }
    2667     if (RT_SUCCESS(rc))
    2668     {
    2669         char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
    2670         if (pszString)
     2661    /*
     2662     * (Don't call CFGMR3QuerySize and CFGMR3QueryStringDef here as the latter
     2663     * cannot handle pszDef being NULL.)
     2664     */
     2665    PCFGMLEAF pLeaf;
     2666    int rc = cfgmR3ResolveLeaf(pNode, pszName, &pLeaf);
     2667    if (RT_SUCCESS(rc))
     2668    {
     2669        if (pLeaf->enmType == CFGMVALUETYPE_STRING)
    26712670        {
    2672             rc = CFGMR3QueryStringDef(pNode, pszName, pszString, cbString, pszDef);
    2673             if (RT_SUCCESS(rc))
     2671            size_t const cbSrc = pLeaf->Value.String.cb;
     2672            char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbSrc);
     2673            if (pszString)
     2674            {
     2675                memcpy(pszString, pLeaf->Value.String.psz, cbSrc);
    26742676                *ppszString = pszString;
     2677            }
    26752678            else
    2676                 MMR3HeapFree(pszString);
     2679                rc = VERR_NO_MEMORY;
    26772680        }
    26782681        else
    2679             rc = VERR_NO_MEMORY;
    2680     }
     2682            rc = VERR_CFGM_NOT_STRING;
     2683    }
     2684    if (RT_FAILURE(rc))
     2685    {
     2686        if (!pszDef)
     2687            *ppszString = NULL;
     2688        else
     2689            *ppszString = MMR3HeapStrDup(pNode->pVM, MM_TAG_CFGM_USER, pszDef);
     2690        if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
     2691            rc = VINF_SUCCESS;
     2692    }
     2693
    26812694    return rc;
    26822695}
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