Bug Summary

File:src/sys/arch/amd64/stand/cdboot/../libsa/time.c
Warning:line 91, column 10
1st function call argument is an uninitialized value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple i386-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name time.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 static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu i586 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/stand/cdboot/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/lib/clang/13.0.0 -D MDRANDOM -D _STANDALONE -D __INTERNAL_LIBSA_CREAD -D OSREV="7.0" -D MACHINE="amd64" -D KERNEL="/7.0/amd64/bsd.rd" -I /usr/src/sys/arch/amd64/stand/cdboot/../../../.. -I /usr/src/sys/arch/amd64/stand/cdboot/../libsa -I . -I /usr/src/sys/arch/amd64/stand/cdboot -D SOFTRAID -D BOOTMAGIC=0xc001d00d -D LINKADDR=0x40120 -D SLOW -D SMALL -D NOBYFOUR -D NO_GZIP -D DYNAMIC_CRC_TABLE -D BUILDFIXED -I /usr/src/sys/arch/amd64/stand/cdboot/../../../../stand/boot -Oz -fdebug-compilation-dir=/usr/src/sys/arch/amd64/stand/cdboot/obj -ferror-limit 19 -fwrapv -fno-builtin -fgnuc-version=4.2.1 -fpack-struct=1 -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 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/sys/arch/amd64/stand/cdboot/../libsa/time.c
1/* $OpenBSD: time.c,v 1.5 2014/09/23 17:59:25 brad Exp $ */
2
3/*
4 * Copyright (c) 1997 Michael Shalayeff
5 * Copyright (c) 1997 Tobias Weingartner
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 */
30
31#include <sys/time.h>
32#include <machine/biosvar.h>
33#include <machine/pio.h>
34#include "libsa.h"
35#include "biosdev.h"
36
37#define isleap(y)((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) ==
0)
((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
38
39/*
40 * Convert from bcd (packed) to int
41 */
42static __inline u_int8_t
43bcdtoint(u_int8_t c)
44{
45 return ((c & 0xf0) / 8) * 5 + (c & 0x0f);
46}
47
48/*
49 * Quick compute of time in seconds since the Epoch
50 */
51const u_short monthcount[] = {
52 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
53};
54
55static __inline time_t
56compute(int year, u_int8_t month, u_int8_t day, u_int8_t hour,
57 u_int8_t min, u_int8_t sec)
58{
59 /* Number of days per month */
60 register time_t tt;
61
62 /* Compute days */
63 tt = (year - 1970) * 365 + monthcount[month] + day - 1;
64
65 /* Compute for leap year */
66 for (month <= 2 ? year-- : 0; year >= 1970; year--)
67 if (isleap(year)((((year) % 4) == 0 && ((year) % 100) != 0) || ((year
) % 400) == 0)
)
68 tt++;
69
70 /* Plus the time */
71 tt = sec + 60 * (min + 60 * (tt * 24 + hour));
72
73 return tt;
74}
75
76static int
77bios_time_date(int f, u_int8_t *b)
78{
79 __asm volatile(DOINT(0x1a)"int $0x20+(" "0x1a" ")" "\n\t"
80 "setc %b0\n\t"
81 "movb %%ch, 0(%2)\n\t"
82 "movb %%cl, 1(%2)\n\t"
83 "movb %%dh, 2(%2)\n\t"
84 "movb %%dl, 3(%2)\n\t"
85 : "=a" (f)
86 : "0" (f), "r" (b) : "%ecx", "%edx", "cc");
87
88 if (f & 0xff)
4
Assuming the condition is false
5
Taking false branch
89 return -1;
90 else {
91 b[0] = bcdtoint(b[0]);
6
1st function call argument is an uninitialized value
92 b[1] = bcdtoint(b[1]);
93 b[2] = bcdtoint(b[2]);
94 b[3] = bcdtoint(b[3]);
95 return 0;
96 }
97}
98
99static __inline int
100biosdate(u_int8_t *b)
101{
102 return bios_time_date(4 << 8, b);
103}
104
105static __inline int
106biostime(u_int8_t *b)
107{
108 return bios_time_date(2 << 8, b);
3
Calling 'bios_time_date'
109}
110
111/*
112 * Return time since epoch
113 */
114time_t
115getsecs(void)
116{
117 u_int8_t timebuf[4], datebuf[4];
118
119 /* Query BIOS for time & date */
120 if (!biostime(timebuf) && !biosdate(datebuf)) {
2
Calling 'biostime'
121#ifdef notdef
122 int dst;
123
124 dst = timebuf[3];
125#endif
126 /* Convert to seconds since Epoch */
127 return compute(datebuf[0] * 100 + datebuf[1], datebuf[2],
128 datebuf[3], timebuf[0], timebuf[1], timebuf[2]);
129 } else
130 errno = EIO5;
131
132 return 1;
133}
134
135u_int
136sleep(u_int i)
137{
138 register time_t t;
139
140 /*
141 * Loop for the requested number of seconds, polling BIOS,
142 * so that it may handle interrupts.
143 */
144 for (t = getsecs() + i; getsecs() < t; cnischar())
1
Calling 'getsecs'
145 ;
146
147 return 0;
148}