VirtualBox

Changeset 11413 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 14, 2008 8:03:03 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34729
Message:

Runtime: small fix to the UUID code, splitting the ClockSeq field and put the UUID variant in the right place. Rest is cleanup and documenting that the IPRT UUIDs are little endian.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/VBox/strformat-vbox.cpp

    r9224 r11413  
    464464                                           pUuid->Gen.u16TimeMid,
    465465                                           pUuid->Gen.u16TimeHiAndVersion,
    466                                            pUuid->Gen.u16ClockSeq & 0xff,
    467                                            pUuid->Gen.u16ClockSeq >> 8,
     466                                           pUuid->Gen.u8ClockSeqHiAndReserved,
     467                                           pUuid->Gen.u8ClockSeqLow,
    468468                                           pUuid->Gen.au8Node[0],
    469469                                           pUuid->Gen.au8Node[1],
  • trunk/src/VBox/Runtime/common/string/strformatrt.cpp

    r9226 r11413  
    458458                                               u.pUuid->Gen.u16TimeMid,
    459459                                               u.pUuid->Gen.u16TimeHiAndVersion,
    460                                                u.pUuid->Gen.u16ClockSeq & 0xff,
    461                                                u.pUuid->Gen.u16ClockSeq >> 8,
     460                                               u.pUuid->Gen.u8ClockSeqHiAndReserved,
     461                                               u.pUuid->Gen.u8ClockSeqLow,
    462462                                               u.pUuid->Gen.au8Node[0],
    463463                                               u.pUuid->Gen.au8Node[1],
  • trunk/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp

    r9744 r11413  
    3939
    4040
    41 /* WARNING: This implementation ASSUMES little endian. Needs testing on big endian! */
     41/* WARNING: This implementation ASSUMES little endian. Does not work on big endian! */
     42
     43/* Remember, the time fields in the UUID must be little endian. */
    4244
    4345
     
    4850
    4951    RTRandBytes(pUuid, sizeof(*pUuid));
    50     pUuid->Gen.u16ClockSeq = (pUuid->Gen.u16ClockSeq & 0x3fff) | 0x8000;
     52    pUuid->Gen.u8ClockSeqHiAndReserved = (pUuid->Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
    5153    pUuid->Gen.u16TimeHiAndVersion = (pUuid->Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
    5254
  • trunk/src/VBox/Runtime/generic/uuid-generic.cpp

    r9743 r11413  
    3838
    3939
    40 /* WARNING: This implementation ASSUMES little endian. Needs testing on big endian! */
     40/* WARNING: This implementation ASSUMES little endian. Does not work on big endian! */
     41
     42/* Remember, the time fields in the UUID must be little endian. */
    4143
    4244
     
    8183    if (pUuid1->Gen.u16TimeHiAndVersion != pUuid2->Gen.u16TimeHiAndVersion)
    8284        return pUuid1->Gen.u16TimeHiAndVersion < pUuid2->Gen.u16TimeHiAndVersion ? -1 : 1;
    83     if (pUuid1->Gen.u16ClockSeq != pUuid2->Gen.u16ClockSeq)
    84         return pUuid1->Gen.u16ClockSeq < pUuid2->Gen.u16ClockSeq ? -1 : 1;
     85    if (pUuid1->Gen.u8ClockSeqHiAndReserved != pUuid2->Gen.u8ClockSeqHiAndReserved)
     86        return pUuid1->Gen.u8ClockSeqHiAndReserved < pUuid2->Gen.u8ClockSeqHiAndReserved ? -1 : 1;
     87    if (pUuid1->Gen.u8ClockSeqLow != pUuid2->Gen.u8ClockSeqLow)
     88        return pUuid1->Gen.u8ClockSeqLow < pUuid2->Gen.u8ClockSeqLow ? -1 : 1;
    8589    if (pUuid1->Gen.au8Node[0] != pUuid2->Gen.au8Node[0])
    8690        return pUuid1->Gen.au8Node[0] < pUuid2->Gen.au8Node[0] ? -1 : 1;
     
    160164    pszString[17] = s_achDigits[(u/*>>0*/)& 0xf];
    161165    pszString[18] = '-';
    162     u = pUuid->Gen.u16ClockSeq;
    163     pszString[19] = s_achDigits[(u >>  4) & 0xf];
    164     pszString[20] = s_achDigits[(u/*>>0*/)& 0xf];
    165     pszString[21] = s_achDigits[(u >> 12)/*& 0xf*/];
    166     pszString[22] = s_achDigits[(u >>  8) & 0xf];
     166    pszString[19] = s_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved >> 4];
     167    pszString[20] = s_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved & 0xf];
     168    pszString[21] = s_achDigits[pUuid->Gen.u8ClockSeqLow >> 4];
     169    pszString[22] = s_achDigits[pUuid->Gen.u8ClockSeqLow & 0xf];
    167170    pszString[23] = '-';
    168171    pszString[24] = s_achDigits[pUuid->Gen.au8Node[0] >> 4];
     
    276279                          | (uint16_t)MY_TONUM(pszString[16]) << 4
    277280                          | (uint16_t)MY_TONUM(pszString[17]);
    278     pUuid->Gen.u16ClockSeq =(uint16_t)MY_TONUM(pszString[19]) << 4
    279                           | (uint16_t)MY_TONUM(pszString[20])
    280                           | (uint16_t)MY_TONUM(pszString[21]) << 12
    281                           | (uint16_t)MY_TONUM(pszString[22]) << 8;
     281    pUuid->Gen.u8ClockSeqHiAndReserved =
     282                            (uint16_t)MY_TONUM(pszString[19]) << 4
     283                          | (uint16_t)MY_TONUM(pszString[20]);
     284    pUuid->Gen.u8ClockSeqLow =
     285                            (uint16_t)MY_TONUM(pszString[21]) << 4
     286                          | (uint16_t)MY_TONUM(pszString[22]);
    282287    pUuid->Gen.au8Node[0] = (uint8_t)MY_TONUM(pszString[24]) << 4
    283288                          | (uint8_t)MY_TONUM(pszString[25]);
  • trunk/src/VBox/Runtime/testcase/tstUuid.cpp

    r11393 r11413  
    9797    Uuid3.au8[14] = 0xdc;
    9898    Uuid3.au8[15] = 0xfe;
    99     Uuid3.Gen.u16ClockSeq = (Uuid3.Gen.u16ClockSeq & 0x3fff) | 0x8000;
     99    Uuid3.Gen.u8ClockSeqHiAndReserved = (Uuid3.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
    100100    Uuid3.Gen.u16TimeHiAndVersion = (Uuid3.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
    101     const char *pszUuid3 = "67452301-ab89-4fcd-10b2-547698badcfe";
     101    const char *pszUuid3 = "67452301-ab89-4fcd-90b2-547698badcfe";
    102102    rc = RTUuidToStr(&Uuid3, sz, sizeof(sz)); CHECK_RC();
    103103    CHECK_EXPR(strcmp(sz, pszUuid3) == 0);
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