From: Ben Pfaff Date: Sun, 5 Sep 2004 08:29:30 +0000 (+0000) Subject: Don't try to allocate file that's too big in filehdr_allocate. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6f0a18e4128aee1b4213faa0d2d655083016b49;p=pintos-anon Don't try to allocate file that's too big in filehdr_allocate. --- diff --git a/src/filesys/filehdr.c b/src/filesys/filehdr.c index 1f35946..d7d2cc2 100644 --- a/src/filesys/filehdr.c +++ b/src/filesys/filehdr.c @@ -22,12 +22,15 @@ filehdr_allocate (struct bitmap *b, off_t length) ASSERT (b != NULL); ASSERT (length >= 0); + sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0); + if (sector_cnt > DIRECT_CNT) + return false; + h = calloc (1, sizeof *h); if (h == NULL) return NULL; h->length = length; - sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0); while (h->sector_cnt < sector_cnt) { size_t sector = bitmap_find_and_set (b);