Bug Summary

File:gotadmin/gotadmin.c
Warning:line 237, column 2
Value stored to 'argv' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd6.9 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name gotadmin.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 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/local/lib/clang/11.1.0 -I /home/ben/Projects/got/gotadmin/../include -I /home/ben/Projects/got/gotadmin/../lib -D GOT_LIBEXECDIR=/home/ben/bin -D GOT_VERSION=0.53-current -internal-isystem /usr/local/lib/clang/11.1.0/include -internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir /home/ben/Projects/got/gotadmin/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -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/got/scan/2021-05-28-230913-68537-1 -x c /home/ben/Projects/got/gotadmin/gotadmin.c
1/*
2 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <sys/queue.h>
18
19#include <getopt.h>
20#include <err.h>
21#include <errno(*__errno()).h>
22#include <locale.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <signal.h>
26#include <string.h>
27#include <unistd.h>
28#include <util.h>
29
30#include "got_version.h"
31#include "got_error.h"
32#include "got_object.h"
33#include "got_reference.h"
34#include "got_repository.h"
35#include "got_gotconfig.h"
36#include "got_path.h"
37#include "got_cancel.h"
38#include "got_privsep.h"
39#include "got_opentemp.h"
40
41#ifndef nitems
42#define nitems(_a)(sizeof((_a)) / sizeof((_a)[0])) (sizeof((_a)) / sizeof((_a)[0]))
43#endif
44
45static volatile sig_atomic_t sigint_received;
46static volatile sig_atomic_t sigpipe_received;
47
48static void
49catch_sigint(int signo)
50{
51 sigint_received = 1;
52}
53
54static void
55catch_sigpipe(int signo)
56{
57 sigpipe_received = 1;
58}
59
60
61struct gotadmin_cmd {
62 const char *cmd_name;
63 const struct got_error *(*cmd_main)(int, char *[]);
64 void (*cmd_usage)(void);
65 const char *cmd_alias;
66};
67
68__dead__attribute__((__noreturn__)) static void usage(int, int);
69__dead__attribute__((__noreturn__)) static void usage_info(void);
70
71static const struct got_error* cmd_info(int, char *[]);
72
73static struct gotadmin_cmd gotadmin_commands[] = {
74 { "info", cmd_info, usage_info, "" },
75};
76
77static void
78list_commands(FILE *fp)
79{
80 size_t i;
81
82 fprintf(fp, "commands:");
83 for (i = 0; i < nitems(gotadmin_commands)(sizeof((gotadmin_commands)) / sizeof((gotadmin_commands)[0])
)
; i++) {
84 struct gotadmin_cmd *cmd = &gotadmin_commands[i];
85 fprintf(fp, " %s", cmd->cmd_name);
86 }
87 fputc('\n', fp);
88}
89
90int
91main(int argc, char *argv[])
92{
93 struct gotadmin_cmd *cmd;
94 size_t i;
95 int ch;
96 int hflag = 0, Vflag = 0;
97 static struct option longopts[] = {
98 { "version", no_argument0, NULL((void *)0), 'V' },
99 { NULL((void *)0), 0, NULL((void *)0), 0 }
100 };
101
102 setlocale(LC_CTYPE2, "");
103
104 while ((ch = getopt_long(argc, argv, "+hV", longopts, NULL((void *)0))) != -1) {
105 switch (ch) {
106 case 'h':
107 hflag = 1;
108 break;
109 case 'V':
110 Vflag = 1;
111 break;
112 default:
113 usage(hflag, 1);
114 /* NOTREACHED */
115 }
116 }
117
118 argc -= optind;
119 argv += optind;
120 optind = 1;
121 optreset = 1;
122
123 if (Vflag) {
124 got_version_print_str();
125 return 0;
126 }
127
128 if (argc <= 0)
129 usage(hflag, hflag ? 0 : 1);
130
131 signal(SIGINT2, catch_sigint);
132 signal(SIGPIPE13, catch_sigpipe);
133
134 for (i = 0; i < nitems(gotadmin_commands)(sizeof((gotadmin_commands)) / sizeof((gotadmin_commands)[0])
)
; i++) {
135 const struct got_error *error;
136
137 cmd = &gotadmin_commands[i];
138
139 if (strcmp(cmd->cmd_name, argv[0]) != 0 &&
140 strcmp(cmd->cmd_alias, argv[0]) != 0)
141 continue;
142
143 if (hflag)
144 gotadmin_commands[i].cmd_usage();
145
146 error = gotadmin_commands[i].cmd_main(argc, argv);
147 if (error && error->code != GOT_ERR_CANCELLED49 &&
148 error->code != GOT_ERR_PRIVSEP_EXIT41 &&
149 !(sigpipe_received &&
150 error->code == GOT_ERR_ERRNO1 && errno(*__errno()) == EPIPE32) &&
151 !(sigint_received &&
152 error->code == GOT_ERR_ERRNO1 && errno(*__errno()) == EINTR4)) {
153 fprintf(stderr(&__sF[2]), "%s: %s\n", getprogname(), error->msg);
154 return 1;
155 }
156
157 return 0;
158 }
159
160 fprintf(stderr(&__sF[2]), "%s: unknown command '%s'\n", getprogname(), argv[0]);
161 list_commands(stderr(&__sF[2]));
162 return 1;
163}
164
165__dead__attribute__((__noreturn__)) static void
166usage(int hflag, int status)
167{
168 FILE *fp = (status == 0) ? stdout(&__sF[1]) : stderr(&__sF[2]);
169
170 fprintf(fp, "usage: %s [-h] [-V | --version] command [arg ...]\n",
171 getprogname());
172 if (hflag)
173 list_commands(fp);
174 exit(status);
175}
176
177static const struct got_error *
178apply_unveil(const char *repo_path, int repo_read_only)
179{
180 const struct got_error *err;
181
182#ifdef PROFILE
183 if (unveil("gmon.out", "rwc") != 0)
184 return got_error_from_errno2("unveil", "gmon.out");
185#endif
186 if (repo_path && unveil(repo_path, repo_read_only ? "r" : "rwc") != 0)
187 return got_error_from_errno2("unveil", repo_path);
188
189 if (unveil(GOT_TMPDIR_STR"/tmp", "rwc") != 0)
190 return got_error_from_errno2("unveil", GOT_TMPDIR_STR"/tmp");
191
192 err = got_privsep_unveil_exec_helpers();
193 if (err != NULL((void *)0))
194 return err;
195
196 if (unveil(NULL((void *)0), NULL((void *)0)) != 0)
197 return got_error_from_errno("unveil");
198
199 return NULL((void *)0);
200}
201
202__dead__attribute__((__noreturn__)) static void
203usage_info(void)
204{
205 fprintf(stderr(&__sF[2]), "usage: %s info [-r repository-path]\n",
206 getprogname());
207 exit(1);
208}
209
210static const struct got_error *
211cmd_info(int argc, char *argv[])
212{
213 const struct got_error *error = NULL((void *)0);
214 char *cwd = NULL((void *)0), *repo_path = NULL((void *)0);
215 struct got_repository *repo = NULL((void *)0);
216 const struct got_gotconfig *gotconfig = NULL((void *)0);
217 int ch, npackfiles, npackedobj, nobj;
218 off_t packsize, loose_size;
219 char scaled[FMT_SCALED_STRSIZE7];
220
221 while ((ch = getopt(argc, argv, "r:")) != -1) {
222 switch (ch) {
223 case 'r':
224 repo_path = realpath(optarg, NULL((void *)0));
225 if (repo_path == NULL((void *)0))
226 return got_error_from_errno2("realpath",
227 optarg);
228 got_path_strip_trailing_slashes(repo_path);
229 break;
230 default:
231 usage_info();
232 /* NOTREACHED */
233 }
234 }
235
236 argc -= optind;
237 argv += optind;
Value stored to 'argv' is never read
238
239#ifndef PROFILE
240 if (pledge("stdio rpath wpath flock proc exec sendfd unveil",
241 NULL((void *)0)) == -1)
242 err(1, "pledge");
243#endif
244 cwd = getcwd(NULL((void *)0), 0);
245 if (cwd == NULL((void *)0)) {
246 error = got_error_from_errno("getcwd");
247 goto done;
248 }
249
250 error = got_repo_open(&repo, repo_path ? repo_path : cwd, NULL((void *)0));
251 if (error)
252 goto done;
253
254 error = apply_unveil(got_repo_get_path_git_dir(repo), 1);
255 if (error)
256 goto done;
257
258 printf("repository: %s\n", got_repo_get_path_git_dir(repo));
259
260 gotconfig = got_repo_get_gotconfig(repo);
261 if (gotconfig) {
262 const struct got_remote_repo *remotes;
263 int i, nremotes;
264 if (got_gotconfig_get_author(gotconfig)) {
265 printf("default author: %s\n",
266 got_gotconfig_get_author(gotconfig));
267 }
268 got_gotconfig_get_remotes(&nremotes, &remotes, gotconfig);
269 for (i = 0; i < nremotes; i++) {
270 printf("remote \"%s\": %s\n", remotes[i].name,
271 remotes[i].url);
272 }
273 }
274
275 error = got_repo_get_packfile_info(&npackfiles, &npackedobj,
276 &packsize, repo);
277 if (error)
278 goto done;
279 printf("pack files: %d\n", npackfiles);
280 if (npackfiles > 0) {
281 if (fmt_scaled(packsize, scaled) == -1) {
282 error = got_error_from_errno("fmt_scaled");
283 goto done;
284 }
285 printf("packed objects: %d\n", npackedobj);
286 printf("packed total size: %s\n", scaled);
287 }
288
289 error = got_repo_get_loose_object_info(&nobj, &loose_size, repo);
290 if (error)
291 goto done;
292 printf("loose objects: %d\n", nobj);
293 if (nobj > 0) {
294 if (fmt_scaled(loose_size, scaled) == -1) {
295 error = got_error_from_errno("fmt_scaled");
296 goto done;
297 }
298 printf("loose total size: %s\n", scaled);
299 }
300done:
301 if (repo)
302 got_repo_close(repo);
303 free(cwd);
304 return error;
305}