| File: | obj-scan-build/libstore/../../libstore/derive.c |
| Location: | line 55, column 26 |
| Description: | Division by zero |
| 1 | /* Calculation of various derived store fields | |||
| 2 | ||||
| 3 | Copyright (C) 1995-97,2001 Free Software Foundation, Inc. | |||
| 4 | Written by Miles Bader <miles@gnu.org> | |||
| 5 | This file is part of the GNU Hurd. | |||
| 6 | ||||
| 7 | The GNU Hurd is free software; you can redistribute it and/or | |||
| 8 | modify it under the terms of the GNU General Public License as | |||
| 9 | published by the Free Software Foundation; either version 2, or (at | |||
| 10 | your option) any later version. | |||
| 11 | ||||
| 12 | The GNU Hurd is distributed in the hope that it will be useful, but | |||
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 15 | General Public License for more details. | |||
| 16 | ||||
| 17 | You should have received a copy of the GNU General Public License | |||
| 18 | along with this program; if not, write to the Free Software | |||
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | |||
| 20 | ||||
| 21 | #include <assert.h> | |||
| 22 | #include <sys/types.h> | |||
| 23 | #include <mach.h> | |||
| 24 | ||||
| 25 | #include "store.h" | |||
| 26 | ||||
| 27 | /* Fills in the values of the various fields in STORE that are derivable from | |||
| 28 | the set of runs & the block size. */ | |||
| 29 | void | |||
| 30 | _store_derive (struct store *store) | |||
| 31 | { | |||
| 32 | unsigned i; | |||
| 33 | struct store_run *runs = store->runs; | |||
| 34 | unsigned num_runs = store->num_runs; | |||
| 35 | size_t bsize = store->block_size; | |||
| 36 | ||||
| 37 | /* BLOCK & SIZE */ | |||
| 38 | store->blocks = 0; | |||
| 39 | store->wrap_src = 0; | |||
| 40 | ||||
| 41 | for (i = 0; i < num_runs; i++) | |||
| ||||
| 42 | { | |||
| 43 | store->wrap_src += runs[i].length; | |||
| 44 | if (runs[i].start >= 0) /* Not a hole */ | |||
| 45 | store->blocks += runs[i].length; | |||
| 46 | } | |||
| 47 | ||||
| 48 | if (store->end == 0) | |||
| 49 | /* END not set; set it using the info from RUNS. */ | |||
| 50 | store->end = store->wrap_src; | |||
| 51 | else if (store->wrap_src < store->end) | |||
| 52 | /* A wrapped disk! RUNS is repeated N times to reach END. Adjust BLOCKS | |||
| 53 | to include all iterations. */ | |||
| 54 | { | |||
| 55 | size_t num_iters = store->end / store->wrap_src; | |||
| ||||
| 56 | store_offset_t last_part_base = num_iters * store->wrap_src; | |||
| 57 | ||||
| 58 | store->blocks *= num_iters; | |||
| 59 | ||||
| 60 | for (i = 0; i < num_runs; i++) | |||
| 61 | if (last_part_base + runs[i].length < store->end) | |||
| 62 | { | |||
| 63 | store->blocks += store->end - (last_part_base + runs[i].length); | |||
| 64 | break; | |||
| 65 | } | |||
| 66 | else if (runs[i].start >= 0) | |||
| 67 | store->blocks += runs[i].length; | |||
| 68 | ||||
| 69 | /* WRAP_DST must be set by the caller. */ | |||
| 70 | } | |||
| 71 | ||||
| 72 | store->size = store->end * bsize; | |||
| 73 | ||||
| 74 | store->log2_block_size = 0; | |||
| 75 | store->log2_blocks_per_page = 0; | |||
| 76 | ||||
| 77 | if (bsize != 0) | |||
| 78 | { | |||
| 79 | while ((1 << store->log2_block_size) < bsize) | |||
| 80 | store->log2_block_size++; | |||
| 81 | assert ((1 << store->log2_block_size) == bsize)(((1 << store->log2_block_size) == bsize) ? (void) ( 0) : __assert_fail ("(1 << store->log2_block_size) == bsize" , "../../libstore/derive.c", 81, __PRETTY_FUNCTION__)); | |||
| 82 | ||||
| 83 | while ((bsize << store->log2_blocks_per_page) < vm_page_size) | |||
| 84 | store->log2_blocks_per_page++; | |||
| 85 | assert ((bsize << store->log2_blocks_per_page) == vm_page_size)(((bsize << store->log2_blocks_per_page) == vm_page_size ) ? (void) (0) : __assert_fail ("(bsize << store->log2_blocks_per_page) == vm_page_size" , "../../libstore/derive.c", 85, __PRETTY_FUNCTION__)); | |||
| 86 | } | |||
| 87 | } |