diff options
-rw-r--r-- | include/hashcomp.h | 4 | ||||
-rw-r--r-- | src/hashcomp.cpp | 11 |
2 files changed, 10 insertions, 5 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index bf1996fac..805929f5d 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -397,7 +397,7 @@ namespace irc * Both freebits and bits will ALWAYS be the * same length. */ - size_t bits_size; + unsigned char bits_size; public: /** Allocate the initial memory for bits and * freebits and zero the memory. @@ -446,7 +446,7 @@ namespace irc * as there are an equal number of bytes allocated * for the freebits array. */ - size_t GetSize(); + unsigned char GetSize(); }; /** The irc_char_traits class is used for RFC-style comparison of strings. diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 4c62390dd..d44ab54c2 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -499,7 +499,7 @@ irc::bitfield irc::dynamicbitmask::Allocate() * should only be allocating bitfields on load, the Toggle and * Get methods are O(1) as these are called much more often. */ - for (size_t i = 0; i < bits_size; i++) + for (unsigned char i = 0; i < bits_size; i++) { /* Yes, this is right. You'll notice we terminate the loop when !current_pos, * this is because we logic shift our bit off the end of unsigned char, and its @@ -515,7 +515,12 @@ irc::bitfield irc::dynamicbitmask::Allocate() } } /* We dont have any free space left, increase by one */ - int old_bits_size = bits_size; + + if (bits_size == 255) + /* Oh dear, cant grow it any further */ + throw std::bad_alloc(); + + unsigned char old_bits_size = bits_size; bits_size++; /* Allocate new bitfield space */ unsigned char* temp_bits = new unsigned char[bits_size]; @@ -591,7 +596,7 @@ bool irc::dynamicbitmask::Get(irc::bitfield &pos) throw ModuleException("irc::dynamicbitmask::Get(): Invalid bitfield, out of range"); } -size_t irc::dynamicbitmask::GetSize() +unsigned char irc::dynamicbitmask::GetSize() { return bits_size; } |