diff --git a/doomsday/libdeng2/include/de/data/stringpool.h b/doomsday/libdeng2/include/de/data/stringpool.h index ef97204dc7..42ea208492 100644 --- a/doomsday/libdeng2/include/de/data/stringpool.h +++ b/doomsday/libdeng2/include/de/data/stringpool.h @@ -61,6 +61,9 @@ namespace de /// String identifier was invalid. @ingroup errors DENG2_ERROR(InvalidIdError); + /// The pool does not have any available identifiers. @ingroup errors + DENG2_ERROR(FullError); + /// String identifier. Each string is assigned its own Id. Because this is /// 32-bit, there can be approximately 4.2 billion unique strings in the pool. typedef duint32 Id; diff --git a/doomsday/libdeng2/src/data/stringpool.cpp b/doomsday/libdeng2/src/data/stringpool.cpp index ce94a96c3a..db2fdb29b2 100644 --- a/doomsday/libdeng2/src/data/stringpool.cpp +++ b/doomsday/libdeng2/src/data/stringpool.cpp @@ -36,6 +36,8 @@ #define EXPORT_ID(i) (duint32(i) + 1) #define IMPORT_ID(i) (Id((i) - 1)) +#define MAXIMUM_VALID_ID (0xffffffff - 1) + namespace de { static String const nullString = "(nullptr)"; @@ -233,6 +235,12 @@ struct StringPool::Instance } else { + if(idMap.size() >= MAXIMUM_VALID_ID) + { + throw StringPool::FullError("StringPool::assignUniqueId", + "Out of valid 32-bit identifiers"); + } + // Expand the idMap. idx = idMap.size(); idMap.push_back(str); // O(1) (amortized)