infra: fix bounds checking in len2order()

This commit is contained in:
Thomas Schoebel-Theuer 2014-04-22 11:34:40 +02:00
parent 21fe963c5e
commit a989a43ecd
1 changed files with 8 additions and 3 deletions

View File

@ -359,12 +359,17 @@ int len2order(int len)
{ {
int order = 0; int order = 0;
if (unlikely(len <= 0)) {
BRICK_ERR("trying to use %d bytes\n", len);
return 0;
}
while ((PAGE_SIZE << order) < len) while ((PAGE_SIZE << order) < len)
order++; order++;
if (unlikely(order > BRICK_MAX_ORDER || len <= 0)) { if (unlikely(order > BRICK_MAX_ORDER)) {
BRICK_ERR("trying to allocate %d bytes (max = %d)\n", len, (int)(PAGE_SIZE << order)); BRICK_ERR("trying to use %d bytes (oder = %d, max = %d)\n", len, order, BRICK_MAX_ORDER);
return -1; return BRICK_MAX_ORDER;
} }
return order; return order;
} }