| File: | obj-scan-build/libstore/../../libstore/zero.c |
| Location: | line 112, column 3 |
| Description: | Value stored to 'type' is never read |
| 1 | /* Zero store backend |
| 2 | |
| 3 | Copyright (C) 1995,96,97,99,2000,01, 02 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 <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include <limits.h> |
| 25 | #include <sys/mman.h> |
| 26 | |
| 27 | #include "store.h" |
| 28 | |
| 29 | static error_t |
| 30 | zero_read (struct store *store, |
| 31 | store_offset_t addr, size_t index, size_t amount, void **buf, |
| 32 | size_t *len) |
| 33 | { |
| 34 | if (*len < amount) |
| 35 | { |
| 36 | *buf = mmap (0, amount, PROT_READ0x04|PROT_WRITE0x02, MAP_ANON0x0002, 0, 0); |
| 37 | if (*buf == MAP_FAILED((void *) -1)) |
| 38 | return errno(*__errno_location ()); |
| 39 | *len = amount; |
| 40 | return 0; |
| 41 | } |
| 42 | else |
| 43 | memset (*buf, 0, amount); |
| 44 | |
| 45 | *len = amount; |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static error_t |
| 50 | zero_write (struct store *store, |
| 51 | store_offset_t addr, size_t index, const void *buf, size_t len, |
| 52 | size_t *amount) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | static error_t |
| 58 | zero_set_size (struct store *store, size_t newsize) |
| 59 | { |
| 60 | return EOPNOTSUPP((0x10 << 26) | ((45) & 0x3fff)); |
| 61 | } |
| 62 | |
| 63 | /* Modify SOURCE to reflect those runs in RUNS, and return it in STORE. */ |
| 64 | error_t |
| 65 | zero_remap (struct store *source, |
| 66 | const struct store_run *runs, size_t num_runs, |
| 67 | struct store **store) |
| 68 | { |
| 69 | /* Because all blocks are the same, a zero store always contains just one |
| 70 | run; here we simply count up the number of blocks specified by RUNS, and |
| 71 | modify SOURCE's one run to reflect that. */ |
| 72 | int i; |
| 73 | store_offset_t length = 0, old_length = source->runs[0].length; |
| 74 | for (i = 0; i < num_runs; i++) |
| 75 | if (runs[i].start < 0 || runs[i].start + runs[i].length >= old_length) |
| 76 | return EINVAL((0x10 << 26) | ((22) & 0x3fff)); |
| 77 | else |
| 78 | length += runs[i].length; |
| 79 | source->runs[0].length = length; |
| 80 | *store = source; |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | error_t |
| 85 | zero_allocate_encoding (const struct store *store, struct store_enc *enc) |
| 86 | { |
| 87 | enc->num_ints += 2; |
| 88 | enc->num_offsets += 1; |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | error_t |
| 93 | zero_encode (const struct store *store, struct store_enc *enc) |
| 94 | { |
| 95 | enc->ints[enc->cur_int++] = store->class->id; |
| 96 | enc->ints[enc->cur_int++] = store->flags; |
| 97 | enc->offsets[enc->cur_offset++] = store->size; |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | error_t |
| 102 | zero_decode (struct store_enc *enc, const struct store_class *const *classes, |
| 103 | struct store **store) |
| 104 | { |
| 105 | store_offset_t size; |
| 106 | int type, flags; |
| 107 | |
| 108 | if (enc->cur_int + 2 > enc->num_ints |
| 109 | || enc->cur_offset + 1 > enc->num_offsets) |
| 110 | return EINVAL((0x10 << 26) | ((22) & 0x3fff)); |
| 111 | |
| 112 | type = enc->ints[enc->cur_int++]; |
Value stored to 'type' is never read | |
| 113 | flags = enc->ints[enc->cur_int++]; |
| 114 | size = enc->offsets[enc->cur_offset++]; |
| 115 | |
| 116 | return store_zero_create (size, flags, store); |
| 117 | } |
| 118 | |
| 119 | static error_t |
| 120 | zero_open (const char *name, int flags, |
| 121 | const struct store_class *const *classes, |
| 122 | struct store **store) |
| 123 | { |
| 124 | if (name) |
| 125 | { |
| 126 | char *end; |
| 127 | store_offset_t size = strtoull (name, &end, 0); |
| 128 | if (end == name || end == NULL((void*)0)) |
| 129 | return EINVAL((0x10 << 26) | ((22) & 0x3fff)); |
| 130 | switch (*end) |
| 131 | { |
| 132 | case 'b': |
| 133 | size *= 512; |
| 134 | break; |
| 135 | case 'k': |
| 136 | case 'K': |
| 137 | size *= 1024; |
| 138 | break; |
| 139 | case 'm': |
| 140 | case 'M': |
| 141 | size *= 1024 * 1024; |
| 142 | break; |
| 143 | case 'g': |
| 144 | case 'G': |
| 145 | size *= 1024 * 1024 * 1024; |
| 146 | break; |
| 147 | } |
| 148 | return store_zero_create (size, flags, store); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | store_offset_t max_offs = ~((store_offset_t)1 |
| 153 | << (CHAR_BIT8 * sizeof (store_offset_t) - 1)); |
| 154 | return store_zero_create (max_offs, flags, store); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | static error_t |
| 159 | zero_validate_name (const char *name, const struct store_class *const *classes) |
| 160 | { |
| 161 | if (name) |
| 162 | { |
| 163 | char *end; |
| 164 | strtoul (name, &end, 0); |
| 165 | return end == name ? EINVAL((0x10 << 26) | ((22) & 0x3fff)) : 0; |
| 166 | } |
| 167 | else |
| 168 | return 0; /* `maximum size' */ |
| 169 | } |
| 170 | |
| 171 | static error_t |
| 172 | zero_map (const struct store *store, vm_prot_t prot, mach_port_t *memobj) |
| 173 | { |
| 174 | *memobj = MACH_PORT_NULL((mach_port_t) 0); |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | const struct store_class |
| 179 | store_zero_class = |
| 180 | { |
| 181 | STORAGE_ZERO, "zero", zero_read, zero_write, zero_set_size, |
| 182 | zero_allocate_encoding, zero_encode, zero_decode, |
| 183 | 0, 0, 0, 0, zero_remap, zero_open, zero_validate_name, |
| 184 | zero_map |
| 185 | }; |
| 186 | STORE_STD_CLASS (zero)static const struct store_class *const store_std_classes_zero [] __attribute__ ((__used__)) __attribute__ ((section ("store_std_classes" ))) = { &store_zero_class }; |
| 187 | |
| 188 | /* Return a new zero store SIZE bytes long in STORE. */ |
| 189 | error_t |
| 190 | store_zero_create (store_offset_t size, int flags, struct store **store) |
| 191 | { |
| 192 | struct store_run run = { 0, size }; |
| 193 | return |
| 194 | _store_create (&store_zero_class, MACH_PORT_NULL((mach_port_t) 0), |
| 195 | flags | STORE_INNOCUOUS0x8000, 1, &run, 1, 0, store); |
| 196 | } |