VirtualBox

Changeset 33464 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Oct 26, 2010 12:27:50 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67055
Message:

*: Fixes for incorrect RTStrAPrintf usage (it does NOT return an IPRT status code) and the odd bugs nearby.

Location:
trunk/src/VBox/Runtime/r3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/env-posix.cpp

    r28800 r33464  
    103103    AssertReturn(!strchr(pszVar, '='), VERR_INVALID_PARAMETER);
    104104
    105     /* Check that it exists first.  */
     105    /*
     106     * Check that it exists first.
     107     */
    106108    if (!RTEnvExist(pszVar))
    107109        return VINF_ENV_VAR_NOT_FOUND;
    108110
    109     /* Ok, try remove it. */
     111    /*
     112     * Ok, try remove it.
     113     */
    110114#ifdef RT_OS_WINDOWS
    111     /* Windows does not have unsetenv(). Clear the environment variable according to the MSN docs. */
    112     char *pszBuf;
    113     int rc = RTStrAPrintf(&pszBuf, "%s=", pszVar);
    114     if (RT_FAILURE(rc))
    115         return rc;
    116     rc = putenv(pszBuf);
    117     RTStrFree(pszBuf);
    118     if (!rc)
     115    /* Use putenv(var=) since Windows does not have unsetenv(). */
     116    size_t cchVar = strlen(pszVar);
     117    char *pszBuf = (char *)alloca(cchVar + 2);
     118    memcpy(pszBuf, pszVar, cchVar);
     119    pszBuf[cchVar]     = '=';
     120    pszBuf[cchVar + 1] = '\0';
     121
     122    if (!putenv(pszBuf))
    119123        return VINF_SUCCESS;
     124
    120125#else
    121126    /* This is the preferred function as putenv() like used above does neither work on Solaris nor on Darwin. */
  • trunk/src/VBox/Runtime/r3/xml.cpp

    r33056 r33464  
    10451045AttributeNode* ElementNode::setAttribute(const char *pcszName, int32_t i)
    10461046{
    1047     char *psz = NULL;
    1048     RTStrAPrintf(&psz, "%RI32", i);
    1049     AttributeNode *p = setAttribute(pcszName, psz);
    1050     RTStrFree(psz);
     1047    char szValue[64];
     1048    RTStrPrintf(szValue, sizeof(szValue), "%RI32", i);
     1049    AttributeNode *p = setAttribute(pcszName, szValue);
    10511050    return p;
    10521051}
    10531052
    1054 AttributeNode* ElementNode::setAttribute(const char *pcszName, uint32_t i)
    1055 {
    1056     char *psz = NULL;
    1057     RTStrAPrintf(&psz, "%RU32", i);
    1058     AttributeNode *p = setAttribute(pcszName, psz);
    1059     RTStrFree(psz);
     1053AttributeNode* ElementNode::setAttribute(const char *pcszName, uint32_t u)
     1054{
     1055    char szValue[64];
     1056    RTStrPrintf(szValue, sizeof(szValue), "%RU32", u);
     1057    AttributeNode *p = setAttribute(pcszName, szValue);
    10601058    return p;
    10611059}
     
    10631061AttributeNode* ElementNode::setAttribute(const char *pcszName, int64_t i)
    10641062{
    1065     char *psz = NULL;
    1066     RTStrAPrintf(&psz, "%RI64", i);
    1067     AttributeNode *p = setAttribute(pcszName, psz);
    1068     RTStrFree(psz);
     1063    char szValue[64];
     1064    RTStrPrintf(szValue, sizeof(szValue), "%RI64", i);
     1065    AttributeNode *p = setAttribute(pcszName, szValue);
    10691066    return p;
    10701067}
    10711068
    1072 AttributeNode* ElementNode::setAttribute(const char *pcszName, uint64_t i)
    1073 {
    1074     char *psz = NULL;
    1075     RTStrAPrintf(&psz, "%RU64", i);
    1076     AttributeNode *p = setAttribute(pcszName, psz);
    1077     RTStrFree(psz);
     1069AttributeNode* ElementNode::setAttribute(const char *pcszName, uint64_t u)
     1070{
     1071    char szValue[64];
     1072    RTStrPrintf(szValue, sizeof(szValue), "%RU64", u);
     1073    AttributeNode *p = setAttribute(pcszName, szValue);
    10781074    return p;
    10791075}
    10801076
    1081 AttributeNode* ElementNode::setAttributeHex(const char *pcszName, uint32_t i)
    1082 {
    1083     char *psz = NULL;
    1084     RTStrAPrintf(&psz, "0x%RX32", i);
    1085     AttributeNode *p = setAttribute(pcszName, psz);
    1086     RTStrFree(psz);
     1077AttributeNode* ElementNode::setAttributeHex(const char *pcszName, uint32_t u)
     1078{
     1079    char szValue[64];
     1080    RTStrPrintf(szValue, sizeof(szValue), "0x%RX32", u);
     1081    AttributeNode *p = setAttribute(pcszName, szValue);
    10871082    return p;
    10881083}
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