VirtualBox

Changeset 5781 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Nov 16, 2007 6:55:05 PM (17 years ago)
Author:
vboxsync
Message:

Fixed some overflow detection issues.

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

Legend:

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

    r5712 r5781  
    3939    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
    4040};
    41 /** Approximated overflow shift checks.
    42  * @todo make the overflow stuff work for real. */
     41/** Approximated overflow shift checks. */
    4342static const char g_auchShift[36] =
    4443{
    4544  /*  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35 */
    46      64, 64, 63, 63, 62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 56, 56, 55, 55, 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 49, 49, 50, 50, 51, 51
     45     64, 64, 63, 63, 62, 62, 62, 62, 61, 61, 61, 61, 61, 61, 61, 61, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 59, 59, 59, 59
    4746};
    4847
     
    573572     * Note: We only support ascii digits at this time... :-)
    574573     */
    575     //int             iShift = g_auchShift[uBase];
     574    int             iShift = g_auchShift[uBase]; /** @todo test this, it's probably not 100% right yet. */
    576575    pszValue = psz; /* (Prefix and sign doesn't count in the digit counting.) */
    577576    int             rc = VINF_SUCCESS;
     
    587586        i64 *= uBase;
    588587        i64 += chDigit;
    589         if (i64Prev > i64/* || (i64Prev >> iShift)*/)
     588        if (i64Prev > i64 || (i64Prev >> iShift))
    590589            rc = VWRN_NUMBER_TOO_BIG;
    591590        psz++;
  • trunk/src/VBox/Runtime/testcase/tstStrToNum.cpp

    r4071 r5781  
    5353
    5454
    55 #define TEST(Test, Type, Fmt, Fun) \
     55#define TEST(Test, Type, Fmt, Fun, iTest) \
    5656    do \
    5757    { \
     
    6060        if (Result != Test.Result) \
    6161        { \
    62             RTPrintf("failure: '%s' -> " Fmt " expected " Fmt ". (%s)\n", Test.psz, Result, Test.Result, #Fun); \
     62            RTPrintf("failure: '%s' -> " Fmt " expected " Fmt ". (%s/%u)\n", Test.psz, Result, Test.Result, #Fun, iTest); \
    6363            cErrors++; \
    6464        } \
    6565        else if (rc != Test.rc) \
    6666        { \
    67             RTPrintf("failure: '%s' -> rc=%Vrc expected %Vrc. (%s)\n", Test.psz, rc, Test.rc, #Fun); \
     67            RTPrintf("failure: '%s' -> rc=%Vrc expected %Vrc. (%s/%u)\n", Test.psz, rc, Test.rc, #Fun, iTest); \
    6868            cErrors++; \
    6969        } \
     
    7676        for (unsigned iTest = 0; iTest < ELEMENTS(aTests); iTest++) \
    7777        { \
    78             TEST(aTests[iTest], Type, Fmt, Fun); \
     78            TEST(aTests[iTest], Type, Fmt, Fun, iTest); \
    7979        } \
    8080    } while (0)
     
    8888        { "1",                      0,  VINF_SUCCESS,           1 },
    8989        { "-1",                     0,  VWRN_NEGATIVE_UNSIGNED,  ~0ULL },
    90         { "0x",                     0,  VINF_SUCCESS,           0 },
     90        { "0x",                     0,  VWRN_TRAILING_CHARS,    0 },
    9191        { "0x1",                    0,  VINF_SUCCESS,           1 },
    9292        { "0x0fffffffffffffff",     0,  VINF_SUCCESS,           0x0fffffffffffffffULL },
     
    9494        { "asdfasdfasdf",           0,  VERR_NO_DIGITS,         0 },
    9595        { "0x111111111",            0,  VINF_SUCCESS,           0x111111111ULL },
     96        { "4D9702C5CBD9B778",      16,  VINF_SUCCESS,           UINT64_C(0x4D9702C5CBD9B778) },
    9697    };
    9798    RUN_TESTS(aTstU64, uint64_t, "%#llx", RTStrToUInt64Ex);
     
    126127        { "-1234567890123456789",   0,  VINF_SUCCESS,          -1234567890123456789LL },
    127128        { "-1234567890123456789",  10,  VINF_SUCCESS,          -1234567890123456789LL },
    128         { "0x",                     0,  VINF_SUCCESS,           0 },
    129         { "0x1",                    0,  VINF_SUCCESS,           1 },
    130         { "0x1",                   10,  VINF_SUCCESS,           0 },
     129        { "0x",                     0,  VWRN_TRAILING_CHARS,    0 },
     130        { "0x1",                    0,  VINF_SUCCESS,           1 },
     131        { "0x1",                   10,  VWRN_TRAILING_CHARS,    0 },
    131132        { "0x1",                   16,  VINF_SUCCESS,           1 },
    132133        { "0x0fffffffffffffff",     0,  VINF_SUCCESS,           0x0fffffffffffffffULL },
    133         //{ "0x01111111111111111111111",0,  VWRN_NUMBER_TOO_BIG,  0x1111111111111111ULL },
     134        { "0x7fffffffffffffff",     0,  VINF_SUCCESS,           0x7fffffffffffffffULL },
     135        { "0xffffffffffffffff",     0,  VWRN_NUMBER_TOO_BIG,    -1 },
     136        { "0x01111111111111111111111",0,  VWRN_NUMBER_TOO_BIG,  0x1111111111111111ULL },
     137        { "0x02222222222222222222222",0,  VWRN_NUMBER_TOO_BIG,  0x2222222222222222ULL },
     138        { "0x03333333333333333333333",0,  VWRN_NUMBER_TOO_BIG,  0x3333333333333333ULL },
     139        { "0x04444444444444444444444",0,  VWRN_NUMBER_TOO_BIG,  0x4444444444444444ULL },
     140        { "0x07777777777777777777777",0,  VWRN_NUMBER_TOO_BIG,  0x7777777777777777ULL },
     141        { "0x07f7f7f7f7f7f7f7f7f7f7f",0,  VWRN_NUMBER_TOO_BIG,  0x7f7f7f7f7f7f7f7fULL },
    134142        { "0x0ffffffffffffffffffffff",0,  VWRN_NUMBER_TOO_BIG,  0xffffffffffffffffULL },
    135143        { "asdfasdfasdf",           0,  VERR_NO_DIGITS,         0 },
     
    173181        { "1234567890123456789",    0,  VWRN_NUMBER_TOO_BIG,   (int32_t)1234567890123456789LL },
    174182        { "1234567890123456789",   10,  VWRN_NUMBER_TOO_BIG,   (int32_t)1234567890123456789LL },
    175         { "0x",                     0,  VINF_SUCCESS,           0 },
    176         { "0x1",                    0,  VINF_SUCCESS,           1 },
    177         { "0x1",                   10,  VINF_SUCCESS,           0 },
     183        { "0x",                     0,  VWRN_TRAILING_CHARS,    0 },
     184        { "0x1",                    0,  VINF_SUCCESS,           1 },
     185        { "0x1",                   10,  VWRN_TRAILING_CHARS,    0 },
    178186        { "0x1",                   16,  VINF_SUCCESS,           1 },
    179         { "0x0fffffffffffffff",     0,  VWRN_NUMBER_TOO_BIG,           0xffffffff },
     187        { "0x7fffffff",             0,  VINF_SUCCESS,           0x7fffffff },
     188        { "0x80000000",             0,  VWRN_NUMBER_TOO_BIG,    INT32_MIN },
     189        { "0xffffffff",             0,  VWRN_NUMBER_TOO_BIG,    -1 },
     190        { "0x0fffffffffffffff",     0,  VWRN_NUMBER_TOO_BIG,    0xffffffff },
    180191        { "0x01111111111111111111111",0,  VWRN_NUMBER_TOO_BIG,  0x11111111 },
    181192        { "0x0ffffffffffffffffffffff",0,  VWRN_NUMBER_TOO_BIG,  0xffffffff },
     
    190201        { "1",                      0,  VINF_SUCCESS,           1 },
    191202        { "-1",                     0,  VWRN_NEGATIVE_UNSIGNED, ~0 },
    192         { "0x",                     0,  VINF_SUCCESS,           0 },
     203        { "0x",                     0,  VWRN_TRAILING_CHARS,    0 },
    193204        { "0x1",                    0,  VINF_SUCCESS,           1 },
    194205        { "0x0fffffffffffffff",     0,  VWRN_NUMBER_TOO_BIG,    0xffffffffU },
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