Bug Summary

File:src/lib/libc/db/btree/bt_conv.c
Warning:line 205, column 2
Value stored to 'p' is never read

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 bt_conv.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 -fhalf-no-semantic-interposition -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/lib/libc/obj -resource-dir /usr/local/lib/clang/13.0.0 -include namespace.h -I /usr/src/lib/libc/include -I /usr/src/lib/libc/hidden -D __LIBC__ -D APIWARN -D YP -I /usr/src/lib/libc/yp -I /usr/src/lib/libc -I /usr/src/lib/libc/gdtoa -I /usr/src/lib/libc/arch/amd64/gdtoa -D INFNAN_CHECK -D MULTIPLE_THREADS -D NO_FENV_H -D USE_LOCALE -I /usr/src/lib/libc -I /usr/src/lib/libc/citrus -D RESOLVSORT -D FLOATING_POINT -D PRINTF_WIDE_CHAR -D SCANF_WIDE_CHAR -D FUTEX -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libc/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/lib/libc/db/btree/bt_conv.c
1/* $OpenBSD: bt_conv.c,v 1.10 2015/01/16 16:48:51 deraadt Exp $ */
2
3/*-
4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Olson.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <stdio.h>
36
37#include <db.h>
38#include "btree.h"
39
40static void mswap(PAGE *);
41
42/*
43 * __BT_BPGIN, __BT_BPGOUT --
44 * Convert host-specific number layout to/from the host-independent
45 * format stored on disk.
46 *
47 * Parameters:
48 * t: tree
49 * pg: page number
50 * h: page to convert
51 */
52void
53__bt_pgin(void *t, pgno_t pg, void *pp)
54{
55 PAGE *h;
56 indx_t i, top;
57 u_char flags;
58 char *p;
59
60 if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)((((BTREE *)t))->flags & (0x00008)))
61 return;
62 if (pg == P_META0) {
63 mswap(pp);
64 return;
65 }
66
67 h = pp;
68 M_32_SWAP(h->pgno){ u_int32_t _tmp = h->pgno; ((char *)&h->pgno)[0] =
((char *)&_tmp)[3]; ((char *)&h->pgno)[1] = ((char
*)&_tmp)[2]; ((char *)&h->pgno)[2] = ((char *)&
_tmp)[1]; ((char *)&h->pgno)[3] = ((char *)&_tmp)[
0]; }
;
69 M_32_SWAP(h->prevpg){ u_int32_t _tmp = h->prevpg; ((char *)&h->prevpg)[
0] = ((char *)&_tmp)[3]; ((char *)&h->prevpg)[1] =
((char *)&_tmp)[2]; ((char *)&h->prevpg)[2] = ((char
*)&_tmp)[1]; ((char *)&h->prevpg)[3] = ((char *)&
_tmp)[0]; }
;
70 M_32_SWAP(h->nextpg){ u_int32_t _tmp = h->nextpg; ((char *)&h->nextpg)[
0] = ((char *)&_tmp)[3]; ((char *)&h->nextpg)[1] =
((char *)&_tmp)[2]; ((char *)&h->nextpg)[2] = ((char
*)&_tmp)[1]; ((char *)&h->nextpg)[3] = ((char *)&
_tmp)[0]; }
;
71 M_32_SWAP(h->flags){ u_int32_t _tmp = h->flags; ((char *)&h->flags)[0]
= ((char *)&_tmp)[3]; ((char *)&h->flags)[1] = ((
char *)&_tmp)[2]; ((char *)&h->flags)[2] = ((char *
)&_tmp)[1]; ((char *)&h->flags)[3] = ((char *)&
_tmp)[0]; }
;
72 M_16_SWAP(h->lower){ u_int16_t _tmp = h->lower; ((char *)&h->lower)[0]
= ((char *)&_tmp)[1]; ((char *)&h->lower)[1] = ((
char *)&_tmp)[0]; }
;
73 M_16_SWAP(h->upper){ u_int16_t _tmp = h->upper; ((char *)&h->upper)[0]
= ((char *)&_tmp)[1]; ((char *)&h->upper)[1] = ((
char *)&_tmp)[0]; }
;
74
75 top = NEXTINDEX(h)(((h)->lower - (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t
) + sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))) / sizeof
(indx_t))
;
76 if ((h->flags & P_TYPE0x1f) == P_BINTERNAL0x01)
77 for (i = 0; i < top; i++) {
78 M_16_SWAP(h->linp[i]){ u_int16_t _tmp = h->linp[i]; ((char *)&h->linp[i]
)[0] = ((char *)&_tmp)[1]; ((char *)&h->linp[i])[1
] = ((char *)&_tmp)[0]; }
;
79 p = (char *)GETBINTERNAL(h, i)((BINTERNAL *)((char *)(h) + (h)->linp[i]));
80 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
81 p += sizeof(u_int32_t);
82 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
83 p += sizeof(pgno_t);
84 if (*(u_char *)p & P_BIGKEY0x02) {
85 p += sizeof(u_char);
86 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
87 p += sizeof(pgno_t);
88 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
89 }
90 }
91 else if ((h->flags & P_TYPE0x1f) == P_BLEAF0x02)
92 for (i = 0; i < top; i++) {
93 M_16_SWAP(h->linp[i]){ u_int16_t _tmp = h->linp[i]; ((char *)&h->linp[i]
)[0] = ((char *)&_tmp)[1]; ((char *)&h->linp[i])[1
] = ((char *)&_tmp)[0]; }
;
94 p = (char *)GETBLEAF(h, i)((BLEAF *)((char *)(h) + (h)->linp[i]));
95 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
96 p += sizeof(u_int32_t);
97 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
98 p += sizeof(u_int32_t);
99 flags = *(u_char *)p;
100 if (flags & (P_BIGKEY0x02 | P_BIGDATA0x01)) {
101 p += sizeof(u_char);
102 if (flags & P_BIGKEY0x02) {
103 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
104 p += sizeof(pgno_t);
105 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
106 }
107 if (flags & P_BIGDATA0x01) {
108 p += sizeof(u_int32_t);
109 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
110 p += sizeof(pgno_t);
111 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
112 }
113 }
114 }
115}
116
117void
118__bt_pgout(void *t, pgno_t pg, void *pp)
119{
120 PAGE *h;
121 indx_t i, top;
122 u_char flags;
123 char *p;
124
125 if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)((((BTREE *)t))->flags & (0x00008)))
126 return;
127 if (pg == P_META0) {
128 mswap(pp);
129 return;
130 }
131
132 h = pp;
133 top = NEXTINDEX(h)(((h)->lower - (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t
) + sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t))) / sizeof
(indx_t))
;
134 if ((h->flags & P_TYPE0x1f) == P_BINTERNAL0x01)
135 for (i = 0; i < top; i++) {
136 p = (char *)GETBINTERNAL(h, i)((BINTERNAL *)((char *)(h) + (h)->linp[i]));
137 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
138 p += sizeof(u_int32_t);
139 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
140 p += sizeof(pgno_t);
141 if (*(u_char *)p & P_BIGKEY0x02) {
142 p += sizeof(u_char);
143 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
144 p += sizeof(pgno_t);
145 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
146 }
147 M_16_SWAP(h->linp[i]){ u_int16_t _tmp = h->linp[i]; ((char *)&h->linp[i]
)[0] = ((char *)&_tmp)[1]; ((char *)&h->linp[i])[1
] = ((char *)&_tmp)[0]; }
;
148 }
149 else if ((h->flags & P_TYPE0x1f) == P_BLEAF0x02)
150 for (i = 0; i < top; i++) {
151 p = (char *)GETBLEAF(h, i)((BLEAF *)((char *)(h) + (h)->linp[i]));
152 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
153 p += sizeof(u_int32_t);
154 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
155 p += sizeof(u_int32_t);
156 flags = *(u_char *)p;
157 if (flags & (P_BIGKEY0x02 | P_BIGDATA0x01)) {
158 p += sizeof(u_char);
159 if (flags & P_BIGKEY0x02) {
160 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
161 p += sizeof(pgno_t);
162 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
163 }
164 if (flags & P_BIGDATA0x01) {
165 p += sizeof(u_int32_t);
166 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
167 p += sizeof(pgno_t);
168 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
;
169 }
170 }
171 M_16_SWAP(h->linp[i]){ u_int16_t _tmp = h->linp[i]; ((char *)&h->linp[i]
)[0] = ((char *)&_tmp)[1]; ((char *)&h->linp[i])[1
] = ((char *)&_tmp)[0]; }
;
172 }
173
174 M_32_SWAP(h->pgno){ u_int32_t _tmp = h->pgno; ((char *)&h->pgno)[0] =
((char *)&_tmp)[3]; ((char *)&h->pgno)[1] = ((char
*)&_tmp)[2]; ((char *)&h->pgno)[2] = ((char *)&
_tmp)[1]; ((char *)&h->pgno)[3] = ((char *)&_tmp)[
0]; }
;
175 M_32_SWAP(h->prevpg){ u_int32_t _tmp = h->prevpg; ((char *)&h->prevpg)[
0] = ((char *)&_tmp)[3]; ((char *)&h->prevpg)[1] =
((char *)&_tmp)[2]; ((char *)&h->prevpg)[2] = ((char
*)&_tmp)[1]; ((char *)&h->prevpg)[3] = ((char *)&
_tmp)[0]; }
;
176 M_32_SWAP(h->nextpg){ u_int32_t _tmp = h->nextpg; ((char *)&h->nextpg)[
0] = ((char *)&_tmp)[3]; ((char *)&h->nextpg)[1] =
((char *)&_tmp)[2]; ((char *)&h->nextpg)[2] = ((char
*)&_tmp)[1]; ((char *)&h->nextpg)[3] = ((char *)&
_tmp)[0]; }
;
177 M_32_SWAP(h->flags){ u_int32_t _tmp = h->flags; ((char *)&h->flags)[0]
= ((char *)&_tmp)[3]; ((char *)&h->flags)[1] = ((
char *)&_tmp)[2]; ((char *)&h->flags)[2] = ((char *
)&_tmp)[1]; ((char *)&h->flags)[3] = ((char *)&
_tmp)[0]; }
;
178 M_16_SWAP(h->lower){ u_int16_t _tmp = h->lower; ((char *)&h->lower)[0]
= ((char *)&_tmp)[1]; ((char *)&h->lower)[1] = ((
char *)&_tmp)[0]; }
;
179 M_16_SWAP(h->upper){ u_int16_t _tmp = h->upper; ((char *)&h->upper)[0]
= ((char *)&_tmp)[1]; ((char *)&h->upper)[1] = ((
char *)&_tmp)[0]; }
;
180}
181
182/*
183 * MSWAP -- Actually swap the bytes on the meta page.
184 *
185 * Parameters:
186 * p: page to convert
187 */
188static void
189mswap(PAGE *pg)
190{
191 char *p;
192
193 p = (char *)pg;
194 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* magic */
195 p += sizeof(u_int32_t);
196 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* version */
197 p += sizeof(u_int32_t);
198 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* psize */
199 p += sizeof(u_int32_t);
200 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* free */
201 p += sizeof(u_int32_t);
202 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* nrecs */
203 p += sizeof(u_int32_t);
204 P_32_SWAP(p){ u_int32_t _tmp = *(u_int32_t *)p; ((char *)p)[0] = ((char *
)&_tmp)[3]; ((char *)p)[1] = ((char *)&_tmp)[2]; ((char
*)p)[2] = ((char *)&_tmp)[1]; ((char *)p)[3] = ((char *)
&_tmp)[0]; }
; /* flags */
205 p += sizeof(u_int32_t);
Value stored to 'p' is never read
206}