Skip to content

Commit

Permalink
libdeng2: StringPool may run out of 32-bit identifiers
Browse files Browse the repository at this point in the history
Added StringPool::FullError.
  • Loading branch information
skyjake committed Nov 26, 2012
1 parent 27ff3b3 commit a5d6a05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doomsday/libdeng2/include/de/data/stringpool.h
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions doomsday/libdeng2/src/data/stringpool.cpp
Expand Up @@ -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)";
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a5d6a05

Please sign in to comment.