Bug Summary

File:shell/main.c
Warning:line 61, column 10
This statement is never executed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.c -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 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/rootdir/shell -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I .. -D LECTORDATADIR="/usr/share/lector" -D CAFEDATADIR="/usr/share" -I .. -I .. -I ../cut-n-paste/zoom-control/ -I ../cut-n-paste/toolbar-editor/ -I ../cut-n-paste/smclient/ -I ../libdocument -I ../libdocument -I ../libview -I ../libview -I ../libmisc -I ../properties -D CAFEICONDIR="/usr/share/pixmaps" -D BINDIR="/usr/bin" -D LIBEXECDIR="/usr/libexec" -D LECTOR_COMPILATION -I /usr/include/libxml2 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/libsecret-1 -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/gio-unix-2.0 -D CDK_MULTIHEAD_SAFE -D CTK_MULTIHEAD_SAFE -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/shell -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-21-192604-54188-1 -x c main.c
1/*
2 * Copyright (C) 2004 Marco Pesenti Gritti
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20#include "config.h"
21
22#include <stdlib.h>
23#include <string.h>
24
25#include <glib/gstdio.h>
26#include <glib/gi18n.h>
27#include <ctk/ctk.h>
28
29#include "ev-application.h"
30#include "ev-debug.h"
31#include "ev-init.h"
32#include "ev-file-helpers.h"
33#include "ev-stock-icons.h"
34#include "ev-metadata.h"
35
36#include "eggsmclient.h"
37#include "eggdesktopfile.h"
38
39
40static gchar *ev_page_label;
41static gchar *ev_find_string;
42static gint ev_page_index = 0;
43static gchar *ev_named_dest;
44static gboolean preview_mode = FALSE(0);
45static gboolean fullscreen_mode = FALSE(0);
46static gboolean presentation_mode = FALSE(0);
47static gboolean unlink_temp_file = FALSE(0);
48static gchar *print_settings;
49static const char **file_arguments = NULL((void*)0);
50
51
52static gboolean
53option_version_cb (const gchar *option_name,
54 const gchar *value,
55 gpointer data,
56 GError **error)
57{
58 g_print ("%s %s\n", _("CAFE Document Viewer")gettext ("CAFE Document Viewer"), VERSION"1.25.0");
59
60 exit (0);
61 return FALSE(0);
This statement is never executed
62}
63
64static const GOptionEntry goption_options[] =
65{
66 { "page-label", 'p', 0, G_OPTION_ARG_STRING, &ev_page_label, N_("The page label of the document to display.")("The page label of the document to display."), N_("PAGE")("PAGE")},
67 { "page-index", 'i', 0, G_OPTION_ARG_INT, &ev_page_index, N_("The page number of the document to display.")("The page number of the document to display."), N_("NUMBER")("NUMBER")},
68 { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen_mode, N_("Run lector in fullscreen mode")("Run lector in fullscreen mode"), NULL((void*)0) },
69 { "named-dest", 'n', 0, G_OPTION_ARG_STRING, &ev_named_dest, N_("Named destination to display.")("Named destination to display."), N_("DEST")("DEST")},
70 { "presentation", 's', 0, G_OPTION_ARG_NONE, &presentation_mode, N_("Run lector in presentation mode")("Run lector in presentation mode"), NULL((void*)0) },
71 { "preview", 'w', 0, G_OPTION_ARG_NONE, &preview_mode, N_("Run lector as a previewer")("Run lector as a previewer"), NULL((void*)0) },
72 { "find", 'l', 0, G_OPTION_ARG_STRING, &ev_find_string, N_("The word or phrase to find in the document")("The word or phrase to find in the document"), N_("STRING")("STRING")},
73 { "unlink-tempfile", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &unlink_temp_file, NULL((void*)0), NULL((void*)0) },
74 { "print-settings", 't', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &print_settings, NULL((void*)0), NULL((void*)0) },
75 { "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, option_version_cb, NULL((void*)0), NULL((void*)0) },
76 { G_OPTION_REMAINING"", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL((void*)0), N_("[FILE…]")("[FILE…]") },
77 { NULL((void*)0) }
78};
79
80static gboolean
81launch_previewer (void)
82{
83 GString *cmd_str;
84 gchar *cmd;
85 gboolean retval = FALSE(0);
86 GError *error = NULL((void*)0);
87
88 /* Rebuild the command line, ignoring options
89 * not supported by the previewer and taking only
90 * the first path given
91 */
92 cmd_str = g_string_new ("lector-previewer");
93
94 if (print_settings) {
95 gchar *quoted;
96
97 quoted = g_shell_quote (print_settings);
98 g_string_append_printf (cmd_str, " --print-settings %s", quoted);
99 g_free (quoted);
100 }
101
102 if (unlink_temp_file)
103 g_string_append (cmd_str, " --unlink-tempfile")(__builtin_constant_p (" --unlink-tempfile") ? __extension__ (
{ const char * const __val = (" --unlink-tempfile"); g_string_append_len_inline
(cmd_str, __val, (__val != ((void*)0)) ? (gssize) strlen (((
__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline
(cmd_str, " --unlink-tempfile", (gssize) -1))
;
104
105 if (file_arguments) {
106 gchar *quoted;
107
108 quoted = g_shell_quote (file_arguments[0]);
109 g_string_append_printf (cmd_str, " %s", quoted);
110 g_free (quoted);
111 }
112
113 cmd = g_string_free (cmd_str, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((cmd_str
), ((0))) : g_string_free_and_steal (cmd_str)) : (g_string_free
) ((cmd_str), ((0))))
;
114
115 if (!error) {
116 GAppInfo *app;
117
118 app = g_app_info_create_from_commandline (cmd, NULL((void*)0), 0, &error);
119
120 if (app != NULL((void*)0)) {
121 retval = g_app_info_launch (app, NULL((void*)0), NULL((void*)0), &error);
122 g_object_unref (app);
123 }
124 }
125
126 if (error) {
127 g_warning ("Error launching previewer: %s\n", error->message);
128 g_error_free (error);
129 }
130
131 g_free (cmd);
132
133 return retval;
134}
135
136static gchar *
137get_label_from_filename (const gchar *filename)
138{
139 GFile *file;
140 gchar *label;
141 gboolean exists;
142
143 label = g_strrstr (filename, "#");
144 if (!label)
145 return NULL((void*)0);
146
147 /* Filename contains a #, check
148 * whether it's part of the path
149 * or a label
150 */
151 file = g_file_new_for_commandline_arg (filename);
152 exists = g_file_query_exists (file, NULL((void*)0));
153 g_object_unref (file);
154
155 return exists ? NULL((void*)0) : label;
156}
157
158static void
159load_files (const char **files)
160{
161 CdkScreen *screen = cdk_screen_get_default ();
162 EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL;
163 gint i;
164 EvLinkDest *global_dest = NULL((void*)0);
165
166 if (!files) {
167 if (!ev_application_has_window (EV_APP((EvApplication *) g_application_get_default ())))
168 ev_application_open_window (EV_APP((EvApplication *) g_application_get_default ()), screen, CDK_CURRENT_TIME0L);
169 return;
170 }
171
172 if (ev_page_label)
173 global_dest = ev_link_dest_new_page_label (ev_page_label);
174 else if (ev_page_index)
175 global_dest = ev_link_dest_new_page (MAX (0, ev_page_index - 1)(((0) > (ev_page_index - 1)) ? (0) : (ev_page_index - 1)));
176 else if (ev_named_dest)
177 global_dest = ev_link_dest_new_named (ev_named_dest);
178
179 if (fullscreen_mode)
180 mode = EV_WINDOW_MODE_FULLSCREEN;
181 else if (presentation_mode)
182 mode = EV_WINDOW_MODE_PRESENTATION;
183
184 for (i = 0; files[i]; i++) {
185 const gchar *filename;
186 gchar *uri;
187 gchar *label;
188 GFile *file;
189 EvLinkDest *dest = NULL((void*)0);
190 const gchar *app_uri;
191
192 filename = files[i];
193 label = get_label_from_filename (filename);
194 if (label) {
195 *label = 0;
196 label++;
197 dest = ev_link_dest_new_page_label (label);
198 } else if (global_dest) {
199 dest = g_object_ref (global_dest)((__typeof__ (global_dest)) (g_object_ref) (global_dest));
200 }
201
202 file = g_file_new_for_commandline_arg (filename);
203 uri = g_file_get_uri (file);
204 g_object_unref (file);
205
206 app_uri = ev_application_get_uri (EV_APP((EvApplication *) g_application_get_default ()));
207 if (app_uri && strcmp (app_uri, uri) == 0) {
208 g_free (uri);
209 continue;
210 }
211
212
213
214 ev_application_open_uri_at_dest (EV_APP((EvApplication *) g_application_get_default ()), uri, screen, dest,
215 mode, ev_find_string,
216 CDK_CURRENT_TIME0L);
217
218 if (dest)
219 g_object_unref (dest);
220 g_free (uri);
221 }
222}
223
224int
225main (int argc, char *argv[])
226{
227 EvApplication *application;
228 GOptionContext *context;
229 GError *error = NULL((void*)0);
230 int status;
231
232#ifdef ENABLE_NLS1
233 /* Initialize the i18n stuff */
234 bindtextdomain (GETTEXT_PACKAGE"lector", ev_get_locale_dir());
235 bind_textdomain_codeset (GETTEXT_PACKAGE"lector", "UTF-8");
236 textdomain (GETTEXT_PACKAGE"lector");
237#endif
238
239 cdk_set_allowed_backends ("x11");
240
241 context = g_option_context_new (N_("CAFE Document Viewer")("CAFE Document Viewer"));
242 g_option_context_set_translation_domain(context, GETTEXT_PACKAGE"lector");
243 g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE"lector");
244 g_option_context_add_group (context, egg_sm_client_get_option_group ());
245 g_option_context_add_group (context, ctk_get_option_group (TRUE(!(0))));
246
247 if (!g_option_context_parse (context, &argc, &argv, &error)) {
248 g_printerr ("Cannot parse arguments: %s\n", error->message);
249 g_error_free (error);
250 g_option_context_free (context);
251
252 return 1;
253 }
254 g_option_context_free (context);
255
256 if (preview_mode) {
257 gboolean retval;
258
259 retval = launch_previewer ();
260
261 return retval ? 0 : 1;
262 }
263
264 if (!ev_init ())
265 return 1;
266
267 ev_stock_icons_init ();
268
269 egg_set_desktop_file (CAFEDATADIR"/usr/share" "/applications/lector.desktop");
270
271 application = ev_application_new ();
272 if (!g_application_register (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((g_application_get_type ()))))))
, NULL((void*)0), &error)) {
273 g_printerr ("Failed to register: %s\n", error->message);
274 g_error_free (error);
275 status = 1;
276 goto done;
277 }
278
279 ev_application_load_session (application);
280 load_files (file_arguments);
281
282 /* Change directory so we don't prevent unmounting in case the initial cwd
283 * is on an external device (see bug #575436)
284 */
285 g_chdir (g_get_home_dir ());
286
287 status = g_application_run (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((g_application_get_type ()))))))
, 0, NULL((void*)0));
288
289 done:
290 ev_shutdown ();
291 ev_stock_icons_shutdown ();
292
293 g_object_unref (application);
294 return status;
295}