VirtualBox

Ignore:
Timestamp:
Sep 10, 2018 7:26:17 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124942
Message:

IPRT/rest: Added testcase for RTCRestDouble, fixing issues found. bugref:9167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp

    r74161 r74170  
    306306
    307307
    308 /** Default destructor. */
     308/** Default constructor. */
    309309RTCRestInt64::RTCRestInt64()
    310310    : RTCRestObjectBase()
     
    470470
    471471
    472 /** Default destructor. */
     472/** Default constructor. */
    473473RTCRestInt32::RTCRestInt32()
    474474    : RTCRestObjectBase()
     
    640640
    641641
    642 /** Default destructor. */
     642/** Default constructor. */
    643643RTCRestInt16::RTCRestInt16()
    644644    : RTCRestObjectBase()
     
    809809}
    810810
    811 /** Default destructor. */
     811/** Default constructor. */
    812812RTCRestDouble::RTCRestDouble()
    813813    : RTCRestObjectBase()
     
    881881        char szValue[128];
    882882#ifdef _MSC_VER
    883         _snprintf(szValue, sizeof(szValue), "%g", m_rdValue);
     883        _snprintf(szValue, sizeof(szValue), "%.18g", m_rdValue);
    884884#else
    885         snprintf(szValue, sizeof(szValue), "%g", m_rdValue);
     885        snprintf(szValue, sizeof(szValue), "%.18g", m_rdValue);
    886886#endif
     887        size_t cchValue = strlen(szValue);
     888        while (cchValue > 0 && szValue[-1] == '0')
     889            cchValue--;
     890        szValue[cchValue] = '\0';
     891
    887892        a_rDst.printf("%s", szValue);
    888893    }
     
    944949        char szValue[128];
    945950#ifdef _MSC_VER
    946         _snprintf(szValue, sizeof(szValue), "%g", m_rdValue);
     951        _snprintf(szValue, sizeof(szValue), "%.18g", m_rdValue);
    947952#else
    948         snprintf(szValue, sizeof(szValue), "%g", m_rdValue);
     953        snprintf(szValue, sizeof(szValue), "%.18g", m_rdValue);
    949954#endif
    950         size_t const cchValue = strlen(szValue);
     955        size_t cchValue = strlen(szValue);
     956        while (cchValue > 0 && szValue[-1] == '0')
     957            cchValue--;
     958        szValue[cchValue] = '\0';
    951959
    952960        if (!(a_fFlags & kToString_Append))
     
    965973{
    966974    RT_NOREF(a_fFlags);
     975
     976    if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive))
     977    {
     978        m_rdValue = 0.0;
     979        m_fNullIndicator = true;
     980        return VINF_SUCCESS;
     981    }
    967982
    968983    m_fNullIndicator = false;
     
    972987    char *pszNext = NULL;
    973988    m_rdValue = strtod(pszValue, &pszNext);
    974     if (errno == 0)
    975         return VINF_SUCCESS;
    976 
    977     if (a_rValue.startsWithWord("null", RTCString::CaseInsensitive))
    978     {
    979         m_rdValue = 0.0;
    980         m_fNullIndicator = true;
    981         return VINF_SUCCESS;
    982     }
    983 
     989    if (errno == 0 && pszNext != pszValue)
     990    {
     991        if (!pszNext || *pszNext == '\0')
     992            return VINF_SUCCESS;
     993
     994        while (RT_C_IS_SPACE(*pszNext))
     995            pszNext++;
     996        if (*pszNext == '\0')
     997            return VINF_SUCCESS;
     998
     999        return RTErrInfoSetF(a_pErrInfo, VERR_TRAILING_CHARS, "%s: error VERR_TRAILING_CHARS parsing '%s' as double",
     1000                             a_pszName, a_rValue.c_str());
     1001    }
     1002
     1003    if (!RT_C_IS_DIGIT(*pszValue) && *pszValue != '.')
     1004        return RTErrInfoSetF(a_pErrInfo, VERR_NO_DIGITS, "%s: error VERR_NO_DIGITS parsing '%s' as double",
     1005                             a_pszName, a_rValue.c_str());
    9841006    int rc = RTErrConvertFromErrno(errno);
    9851007    return RTErrInfoSetF(a_pErrInfo, rc, "%s: error %Rrc parsing '%s' as double", a_pszName, rc, a_rValue.c_str());
     
    10111033
    10121034
    1013 /** Default destructor. */
     1035/** Default constructor. */
    10141036RTCRestString::RTCRestString()
    10151037    : RTCString()
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