Bug Summary

File:src/usr.sbin/makefs/ffs/ufs_bmap.c
Warning:line 112, column 15
Although the value stored to 'off' is used in the enclosing expression, the value is never actually read from 'off'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ufs_bmap.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/usr.sbin/makefs/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/usr.sbin/makefs -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/usr.sbin/makefs/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/usr.sbin/makefs/ffs/ufs_bmap.c
1/* $OpenBSD: ufs_bmap.c,v 1.7 2021/10/06 00:40:41 deraadt Exp $ */
2/* $NetBSD: ufs_bmap.c,v 1.18 2013/06/19 17:51:27 dholland Exp $ */
3/* From: NetBSD: ufs_bmap.c,v 1.14 2001/11/08 05:00:51 chs Exp */
4
5/*
6 * Copyright (c) 1989, 1991, 1993
7 * The Regents of the University of California. All rights reserved.
8 * (c) UNIX System Laboratories, Inc.
9 * All or some portions of this file are derived from material licensed
10 * to the University of California by American Telephone and Telegraph
11 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12 * the permission of UNIX System Laboratories, Inc.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)ufs_bmap.c 8.8 (Berkeley) 8/11/95
39 */
40
41#include <sys/time.h>
42
43#include <assert.h>
44#include <errno(*__errno()).h>
45#include <strings.h>
46
47#include "makefs.h"
48
49#include <ufs/ufs/dinode.h>
50#include <ufs/ffs/fs.h>
51
52#include "ffs/ufs_inode.h"
53#include "ffs/ffs_extern.h"
54
55/*
56 * Create an array of logical block number/offset pairs which represent the
57 * path of indirect blocks required to access a data block. The first "pair"
58 * contains the logical block number of the appropriate single, double or
59 * triple indirect block and the offset into the inode indirect block array.
60 * Note, the logical block number of the inode single/double/triple indirect
61 * block appears twice in the array, once with the offset into the i_ffs_ib and
62 * once with the offset into the page itself.
63 */
64int
65ufs_getlbns(struct inode *ip, daddr_t bn, struct indir *ap, int *nump)
66{
67 daddr_t metalbn, realbn;
68 int64_t blockcnt;
69 int lbc;
70 int i, numlevels, off;
71 u_long lognindir;
72
73 lognindir = ffs(NINDIR(ip->i_fs)((ip->i_fs)->fs_nindir)) - 1;
74 if (nump)
75 *nump = 0;
76 numlevels = 0;
77 realbn = bn;
78 if ((long)bn < 0)
79 bn = -(long)bn;
80
81 assert (bn >= NDADDR)((bn >= 12) ? (void)0 : __assert2("/usr/src/usr.sbin/makefs/ffs/ufs_bmap.c"
, 81, __func__, "bn >= NDADDR"))
;
82
83 /*
84 * Determine the number of levels of indirection. After this loop
85 * is done, blockcnt indicates the number of data blocks possible
86 * at the given level of indirection, and NIADDR - i is the number
87 * of levels of indirection needed to locate the requested block.
88 */
89
90 bn -= NDADDR12;
91 for (lbc = 0, i = NIADDR3;; i--, bn -= blockcnt) {
92 if (i == 0)
93 return (EFBIG27);
94
95 lbc += lognindir;
96 blockcnt = (int64_t)1 << lbc;
97
98 if (bn < blockcnt)
99 break;
100 }
101
102 /* Calculate the address of the first meta-block. */
103 metalbn = -((realbn >= 0 ? realbn : -realbn) - bn + NIADDR3 - i);
104
105 /*
106 * At each iteration, off is the offset into the bap array which is
107 * an array of disk addresses at the current level of indirection.
108 * The logical block number and the offset in that block are stored
109 * into the argument array.
110 */
111 ap->in_lbn = metalbn;
112 ap->in_off = off = NIADDR3 - i;
Although the value stored to 'off' is used in the enclosing expression, the value is never actually read from 'off'
113 ap->in_exists = 0;
114 ap++;
115 for (++numlevels; i <= NIADDR3; i++) {
116 /* If searching for a meta-data block, quit when found. */
117 if (metalbn == realbn)
118 break;
119
120 lbc -= lognindir;
121 blockcnt = (int64_t)1 << lbc;
122 off = (bn >> lbc) & (NINDIR(ip->i_fs)((ip->i_fs)->fs_nindir) - 1);
123
124 ++numlevels;
125 ap->in_lbn = metalbn;
126 ap->in_off = off;
127 ap->in_exists = 0;
128 ++ap;
129
130 metalbn -= -1 + (off << lbc);
131 }
132 if (nump)
133 *nump = numlevels;
134 return (0);
135}