diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-18 00:32:35 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-11-18 00:32:35 +0000 |
commit | 77300844a4607a7ad97e0a1c0907770f22e7b4af (patch) | |
tree | 840b1a17c77e16e42791693d07848d1fff6c0ea9 /src | |
parent | 8827eca1daf82ac647a87b10f2aa1104faf17ef9 (diff) |
Reduce size of max number of bytes in a bitfield from a 4 or 8 byte field to a 1 byte field (unsigned char).
This still allows storage of 8*255 bits, which is MORE than enough (for the interested, its 2040 bits)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5761 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/hashcomp.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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; } |