Changeset 80373 in vbox for trunk/include/VBox
- Timestamp:
- Aug 21, 2019 2:51:02 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/array.h
r76585 r80373 224 224 { 225 225 226 /** Used for dummy element access in com::SafeArray, avoiding crashes. */ 227 extern const char Zeroes[16]; 228 229 226 230 #ifdef VBOX_WITH_XPCOM 227 231 … … 618 622 * Creates a null array. 619 623 */ 620 SafeArray() { }624 SafeArray() { } 621 625 622 626 /** … … 734 738 AssertReturnVoid(!isNull()); 735 739 736 int i = 0;740 size_t i = 0; 737 741 for (typename Map::const_iterator it = aMap.begin(); 738 742 it != aMap.end(); ++ it, ++ i) … … 935 939 /** 936 940 * Array access operator that returns an array element by reference. A bit 937 * safer than #raw(): asserts and returns an invalid reference if this 938 * instance is null or if the index is out of bounds. 941 * safer than #raw(): asserts and returns a reference to a static zero 942 * element (const, i.e. writes will fail) if this instance is null or 943 * if the index is out of bounds. 939 944 * 940 945 * @note For weak instances, this call will succeed but the behavior of … … 944 949 T &operator[] (size_t aIdx) 945 950 { 946 AssertReturn(m.arr != NULL, *((T *)NULL)); 947 AssertReturn(aIdx < size(), *((T *)NULL)); 951 /** @todo r=klaus should do this as a AssertCompile, but cannot find a way which works. */ 952 Assert(sizeof(T) <= sizeof(Zeroes)); 953 AssertReturn(m.arr != NULL, *(T *)&Zeroes[0]); 954 AssertReturn(aIdx < size(), *(T *)&Zeroes[0]); 948 955 #ifdef VBOX_WITH_XPCOM 949 956 return m.arr[aIdx]; 950 957 #else 951 AssertReturn(m.raw != NULL, *((T *)NULL));958 AssertReturn(m.raw != NULL, *(T *)&Zeroes[0]); 952 959 return m.raw[aIdx]; 953 960 #endif … … 959 966 const T operator[] (size_t aIdx) const 960 967 { 961 AssertReturn(m.arr != NULL, *((T *)1));962 AssertReturn(aIdx < size(), *( (T *)1));968 AssertReturn(m.arr != NULL, *(const T *)&Zeroes[0]); 969 AssertReturn(aIdx < size(), *(const T *)&Zeroes[0]); 963 970 #ifdef VBOX_WITH_XPCOM 964 971 return m.arr[aIdx]; 965 972 #else 966 AssertReturn(m.raw != NULL, *((T *)NULL));973 AssertReturn(m.raw != NULL, *(const T *)&Zeroes[0]); 967 974 return m.raw[aIdx]; 968 975 #endif … … 1377 1384 public: 1378 1385 1379 nsIDRef(nsID * &aVal) : mVal(aVal) { }1380 1381 operator const nsID &() const { return mVal ? *mVal : * Empty; }1382 operator nsID() const { return mVal ? *mVal : * Empty; }1383 1384 const nsID *operator&() const { return mVal ? mVal : Empty; }1386 nsIDRef(nsID * &aVal) : mVal(aVal) { AssertCompile(sizeof(nsID) <= sizeof(Zeroes)); } 1387 1388 operator const nsID &() const { return mVal ? *mVal : *(const nsID *)&Zeroes[0]; } 1389 operator nsID() const { return mVal ? *mVal : *(nsID *)&Zeroes[0]; } 1390 1391 const nsID *operator&() const { return mVal ? mVal : (const nsID *)&Zeroes[0]; } 1385 1392 1386 1393 nsIDRef &operator= (const nsID &aThat) … … 1397 1404 nsID * &mVal; 1398 1405 1399 static const nsID *Empty;1400 1401 1406 friend class SafeGUIDArray; 1402 1407 }; … … 1430 1435 Assert(m.arr != NULL); 1431 1436 Assert(aIdx < size()); 1432 return m.arr[aIdx] ? *m.arr[aIdx] : * nsIDRef::Empty;1437 return m.arr[aIdx] ? *m.arr[aIdx] : *(const nsID *)&Zeroes[0]; 1433 1438 } 1434 1439 }; … … 1448 1453 1449 1454 /** See SafeArray<>::SafeArray(). */ 1450 SafeConstGUIDArray() { }1455 SafeConstGUIDArray() { AssertCompile(sizeof(nsID) <= sizeof(Zeroes)); } 1451 1456 1452 1457 /* See SafeArray<>::SafeArray(ComSafeArrayIn(T, aArg)). */ … … 1463 1468 const nsID &operator[] (size_t aIdx) const 1464 1469 { 1465 AssertReturn(m.arr != NULL, * *((const nsID * *)1));1466 AssertReturn(aIdx < size(), * *((const nsID * *)1));1470 AssertReturn(m.arr != NULL, *(const nsID *)&Zeroes[0]); 1471 AssertReturn(aIdx < size(), *(const nsID *)&Zeroes[0]); 1467 1472 return *m.arr[aIdx]; 1468 1473 } … … 1656 1661 AssertReturnVoid(!Base::isNull()); 1657 1662 1658 int i = 0;1663 size_t i = 0; 1659 1664 for (typename List::const_iterator it = aCntr.begin(); 1660 1665 it != aCntr.end(); ++ it, ++ i) … … 1685 1690 AssertReturnVoid(!Base::isNull()); 1686 1691 1687 int i = 0;1692 size_t i = 0; 1688 1693 for (typename List::const_iterator it = aCntr.begin(); 1689 1694 it != aCntr.end(); ++ it, ++ i) … … 1717 1722 AssertReturnVoid(!Base::isNull()); 1718 1723 1719 int i = 0;1724 size_t i = 0; 1720 1725 for (typename Map::const_iterator it = aMap.begin(); 1721 1726 it != aMap.end(); ++ it, ++ i) … … 1749 1754 AssertReturnVoid(!Base::isNull()); 1750 1755 1751 int i = 0;1756 size_t i = 0; 1752 1757 for (typename Map::const_iterator it = aMap.begin(); 1753 1758 it != aMap.end(); ++ it, ++ i)
Note:
See TracChangeset
for help on using the changeset viewer.