X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..5ea0322b6ab2af986e4c764284141380031dd014:/icuSources/common/uvectr32.h?ds=sidebyside diff --git a/icuSources/common/uvectr32.h b/icuSources/common/uvectr32.h index 68a3ee2e..d03eba62 100644 --- a/icuSources/common/uvectr32.h +++ b/icuSources/common/uvectr32.h @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (C) 1999-2006, International Business Machines +* Copyright (C) 1999-2011, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** */ @@ -61,6 +61,8 @@ private: int32_t count; int32_t capacity; + + int32_t maxCapacity; // Limit beyond which capacity is not permitted to grow. int32_t* elements; @@ -161,6 +163,14 @@ public: */ int32_t *getBuffer() const; + /** + * Set the maximum allowed buffer capacity for this vector/stack. + * Default with no limit set is unlimited, go until malloc() fails. + * A Limit of zero means unlimited capacity. + * Units are vector elements (32 bits each), not bytes. + */ + void setMaxCapacity(int32_t limit); + /** * ICU "poor man's RTTI", returns a UClassID for this class. */ @@ -201,7 +211,7 @@ public: // UVector32 inlines inline UBool UVector32::ensureCapacity(int32_t minimumCapacity, UErrorCode &status) { - if (capacity >= minimumCapacity) { + if ((minimumCapacity >= 0) && (capacity >= minimumCapacity)) { return TRUE; } else { return expandCapacity(minimumCapacity, status); @@ -209,7 +219,7 @@ inline UBool UVector32::ensureCapacity(int32_t minimumCapacity, UErrorCode &stat } inline int32_t UVector32::elementAti(int32_t index) const { - return (0 <= index && index < count) ? elements[index] : 0; + return (index >= 0 && count > 0 && count - index > 0) ? elements[index] : 0; } @@ -221,7 +231,9 @@ inline void UVector32::addElement(int32_t elem, UErrorCode &status) { } inline int32_t *UVector32::reserveBlock(int32_t size, UErrorCode &status) { - ensureCapacity(count+size, status); + if (ensureCapacity(count+size, status) == FALSE) { + return NULL; + } int32_t *rp = elements+count; count += size; return rp;