VirtualBox

Ignore:
Timestamp:
Sep 9, 2018 1:53:25 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/strtonum: Fixed problem handling INT64_MIN in RTStrToInt64Ex and friends.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strtonum.cpp

    r69111 r74160  
    557557    int           iShift;
    558558    int           rc;
    559     int64_t       i64;
     559    uint64_t      u64;
    560560    unsigned char uch;
    561561
     
    605605     * Note: We only support ascii digits at this time... :-)
    606606     */
    607     iShift = g_auchShift[uBase]; /** @todo test this, it's probably not 100% right yet. */
     607    iShift = g_auchShift[uBase];
    608608    pszValue = psz; /* (Prefix and sign doesn't count in the digit counting.) */
    609609    rc = VINF_SUCCESS;
    610     i64 = 0;
     610    u64 = 0;
    611611    while ((uch = (unsigned char)*psz) != 0)
    612612    {
    613613        unsigned char chDigit = g_auchDigits[uch];
    614         int64_t i64Prev;
     614        uint64_t u64Prev;
    615615
    616616        if (chDigit >= uBase)
    617617            break;
    618618
    619         i64Prev = i64;
    620         i64 *= uBase;
    621         i64 += chDigit;
    622         if (i64Prev > i64 || (i64Prev >> iShift))
     619        u64Prev = u64;
     620        u64 *= uBase;
     621        u64 += chDigit;
     622        if (u64Prev > u64 || (u64Prev >> iShift))
    623623            rc = VWRN_NUMBER_TOO_BIG;
    624624        psz++;
    625625    }
    626626
    627     if (!fPositive)
    628         i64 = -i64;
     627    if (   !(u64 & RT_BIT_64(63))
     628        || (!fPositive && u64 == RT_BIT_64(63)) )
     629    { /* likely */ }
     630    else
     631        rc = VWRN_NUMBER_TOO_BIG;
    629632
    630633    if (pi64)
    631         *pi64 = i64;
     634        *pi64 = fPositive ? u64 : -(int64_t)u64;
    632635
    633636    if (psz == pszValue)
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