vm: fix integer overflow

db4
Slava Pestov 2009-10-09 05:53:55 -05:00
parent ab9b462411
commit 639a64c2df
2 changed files with 9 additions and 8 deletions

View File

@ -13,8 +13,9 @@ void heap::clear_free_list()
heap::heap(bool secure_gc_, cell size) : secure_gc(secure_gc_)
{
if(size > (1L << (sizeof(cell) * 8 - 6))) fatal_error("Heap too large",size);
seg = new segment(align_page(size));
if(!seg) fatal_error("Out of memory in new_heap",size);
if(!seg) fatal_error("Out of memory in heap allocator",size);
clear_free_list();
}

View File

@ -64,9 +64,9 @@ inline static cell align8(cell a)
#define TYPE_COUNT 15
/* Not a real type, but code_block's type field can be set to this */
#define PIC_TYPE 42
#define FREE_BLOCK_TYPE 69
/* Not real types, but code_block's type can be set to this */
#define PIC_TYPE 16
#define FREE_BLOCK_TYPE 17
/* Constants used when floating-point trap exceptions are thrown */
enum
@ -213,16 +213,16 @@ struct heap_block
header &= ~1;
}
cell type() { return (header >> 1) & 0x7f; }
cell type() { return (header >> 1) & 0x1f; }
void set_type(cell type)
{
header = ((header & ~(0x7f << 1)) | (type << 1));
header = ((header & ~(0x1f << 1)) | (type << 1));
}
cell size() { return (header >> 8); }
cell size() { return (header >> 6); }
void set_size(cell size)
{
header = (header & 0xff) | (size << 8);
header = (header & 0x2f) | (size << 6);
}
};