Commit ac8f3a75 authored by gauthier's avatar gauthier

PGWC: bug dynamic allocation

parent b9eec8ac
...@@ -92,7 +92,9 @@ protected: ...@@ -92,7 +92,9 @@ protected:
std::bitset<32> bs(alloc[bit_pos32]); std::bitset<32> bs(alloc[bit_pos32]);
bs.reset(word_bit_pos); bs.reset(word_bit_pos);
alloc[bit_pos32] = bs.to_ulong(); alloc[bit_pos32] = bs.to_ulong();
return true;
} }
return false;
} }
public: public:
...@@ -121,7 +123,8 @@ public: ...@@ -121,7 +123,8 @@ public:
{ {
int bit_pos = 0; int bit_pos = 0;
if (alloc_free_bit(bit_pos)) { if (alloc_free_bit(bit_pos)) {
allocated.s_addr = start.s_addr + htobe32(bit_pos); allocated.s_addr = be32toh(start.s_addr) + bit_pos; // overflow
allocated.s_addr = htobe32(allocated.s_addr);
return true; return true;
} }
allocated.s_addr = 0; allocated.s_addr = 0;
...@@ -132,8 +135,7 @@ public: ...@@ -132,8 +135,7 @@ public:
{ {
if (in_pool(allocated)) { if (in_pool(allocated)) {
int bit_pos = be32toh(allocated.s_addr) - be32toh(start.s_addr); int bit_pos = be32toh(allocated.s_addr) - be32toh(start.s_addr);
free_bit(bit_pos); return free_bit(bit_pos);
return true;
} }
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment