Changeset 58019 in vbox
- Timestamp:
- Oct 3, 2015 7:31:41 PM (9 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/USBIdDatabase.h
r58017 r58019 158 158 static uint32_t lookupVendor(uint16_t idVendor) 159 159 { 160 size_t iStart = 0;161 160 size_t iEnd = s_cVendors; 162 for (;;) 163 { 164 size_t idx = iStart + (iEnd - iStart) / 2; 165 if (s_aVendors[idx].idVendor < idVendor) 166 { 167 idx++; 168 if (idx < iEnd) 169 iStart = idx; 161 if (iEnd) 162 { 163 size_t iStart = 0; 164 for (;;) 165 { 166 size_t idx = iStart + (iEnd - iStart) / 2; 167 if (s_aVendors[idx].idVendor < idVendor) 168 { 169 idx++; 170 if (idx < iEnd) 171 iStart = idx; 172 else 173 break; 174 } 175 else if (s_aVendors[idx].idVendor > idVendor) 176 { 177 if (idx != iStart) 178 iEnd = idx; 179 else 180 break; 181 } 170 182 else 171 return UINT32_MAX; 172 } 173 else if (s_aVendors[idx].idVendor > idVendor) 174 { 175 if (idx != iStart) 176 iEnd = idx; 177 else 178 return UINT32_MAX; 179 } 180 else 181 return (uint32_t)idx; 182 } 183 return (uint32_t)idx; 184 } 185 } 186 return UINT32_MAX; 183 187 } 184 188 … … 193 197 static uint32_t lookupProduct(uint16_t idProduct, size_t iStart, size_t iEnd) 194 198 { 195 for (;;) 196 { 197 size_t idx = iStart + (iEnd - iStart) / 2; 198 if (s_aProducts[idx].idProduct < idProduct) 199 { 200 idx++; 201 if (idx < iEnd) 202 iStart = idx; 199 if (iStart < iEnd) 200 { 201 for (;;) 202 { 203 size_t idx = iStart + (iEnd - iStart) / 2; 204 if (s_aProducts[idx].idProduct < idProduct) 205 { 206 idx++; 207 if (idx < iEnd) 208 iStart = idx; 209 else 210 break; 211 } 212 else if (s_aProducts[idx].idProduct > idProduct) 213 { 214 if (idx != iStart) 215 iEnd = idx; 216 else 217 break; 218 } 203 219 else 204 return UINT32_MAX; 205 } 206 else if (s_aProducts[idx].idProduct > idProduct) 207 { 208 if (idx != iStart) 209 iEnd = idx; 210 else 211 return UINT32_MAX; 212 } 213 else 214 return (uint32_t)idx; 215 } 220 return (uint32_t)idx; 221 } 222 } 223 return UINT32_MAX; 216 224 } 217 225 -
trunk/src/VBox/Main/src-server/USBIdDatabaseGenerator.cpp
r58018 r58019 581 581 { 582 582 size_t iIdx; 583 size_t iStart = 0; 584 size_t iEnd = g_cSortedStrings; 585 for (;;) 586 { 587 iIdx = iStart + (iEnd - iStart) / 2; 588 if (g_papSortedStrings[iIdx]->StrRef.cch < pStr->StrRef.cch) 589 { 590 if (iIdx <= iStart) 583 size_t iEnd = g_cSortedStrings; 584 if (iEnd) 585 { 586 size_t iStart = 0; 587 for (;;) 588 { 589 iIdx = iStart + (iEnd - iStart) / 2; 590 if (g_papSortedStrings[iIdx]->StrRef.cch < pStr->StrRef.cch) 591 { 592 if (iIdx <= iStart) 593 break; 594 iEnd = iIdx; 595 } 596 else if (g_papSortedStrings[iIdx]->StrRef.cch > pStr->StrRef.cch) 597 { 598 if (++iIdx >= iEnd) 599 break; 600 iStart = iIdx; 601 } 602 else 591 603 break; 592 iEnd = iIdx; 593 } 594 else if (g_papSortedStrings[iIdx]->StrRef.cch > pStr->StrRef.cch) 595 { 596 if (++iIdx >= g_cSortedStrings) 597 break; 598 iStart = iIdx; 599 } 600 else 601 break; 602 } 603 604 if (iIdx != g_cSortedStrings) 605 memmove(&g_papSortedStrings[iIdx + 1], &g_papSortedStrings[iIdx], 606 (g_cSortedStrings - iIdx) * sizeof(g_papSortedStrings[iIdx])); 604 } 605 606 if (iIdx != g_cSortedStrings) 607 memmove(&g_papSortedStrings[iIdx + 1], &g_papSortedStrings[iIdx], 608 (g_cSortedStrings - iIdx) * sizeof(g_papSortedStrings[iIdx])); 609 } 610 else 611 iIdx = 0; 612 607 613 g_papSortedStrings[iIdx] = pStr; 608 614 g_cSortedStrings++; … … 704 710 /* 705 711 * See if the start of the string overlaps the end of the string table. 706 * (Currently saves 1 byte...)707 712 */ 708 713 if (g_cchStrTab && cchCur > 1) … … 715 720 if (!pchCandidate) 716 721 break; 717 if (memcmp(pchCandidate, pszCur, cchLeft) == 0) 722 cchLeft -= pchCandidate - pchLeft; 723 pchLeft = pchCandidate; 724 if (memcmp(pchLeft, pszCur, cchLeft) == 0) 718 725 { 719 726 size_t cchToCopy = cchCur - cchLeft; … … 723 730 break; 724 731 } 725 726 cchLeft -= pchCandidate + 1 - pchLeft; 727 pchLeft = pchCandidate + 1; 732 cchLeft--; 733 pchLeft++; 728 734 } 729 735 } … … 966 972 } 967 973 product.key = RT_MAKE_U32(product.productID, product.vendorID); 968 Assert(product.vendorID != 0);974 Assert(product.vendorID == vendor.vendorID); 969 975 g_products.push_back(product); 970 976 } … … 1085 1091 do 1086 1092 iProduct++; 1087 while (g_products[iProduct].vendorID == idVendor); 1093 while ( iProduct < g_products.size() 1094 && g_products[iProduct].vendorID == idVendor); 1088 1095 else 1089 1096 {
Note:
See TracChangeset
for help on using the changeset viewer.