Bug Summary

File:_build/../tests/pixbuf-threads.c
Warning:line 46, column 16
File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name pixbuf-threads.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=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/_build -fcoverage-compilation-dir=/rootdir/_build -resource-dir /usr/lib/llvm-21/lib/clang/21 -I tests/pixbuf-threads.p -I tests -I ../tests -I . -I .. -I cdk-pixbuf -I ../cdk-pixbuf -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -D _FILE_OFFSET_BITS=64 -D _POSIX_C_SOURCE=200809L -D _DEFAULT_SOURCE -D _XOPEN_SOURCE=700 -D HAVE_CONFIG_H=1 -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/15/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-int-conversion -Wno-uninitialized -Wno-discarded-qualifiers -std=gnu99 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-checker deadcode.DeadStores -analyzer-checker security.ArrayBound -analyzer-checker unix.cstring.NotNullTerminated -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -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/2026-06-05-220802-8580-1 -x c ../tests/pixbuf-threads.c
1/* -*- Mode: C; c-basic-offset: 2; -*- */
2/* CdkPixbuf library - test loaders
3 *
4 * Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "config.h"
21#include <glib/gstdio.h>
22#include "cdk-pixbuf/cdk-pixbuf.h"
23#include "test-common.h"
24
25static void
26load_image (gpointer data,
27 gpointer user_data)
28{
29 gchar *filename = data;
30 const gchar *path;
31 FILE *file;
32 int nbytes;
33 guchar buffer[1024];
34 CdkPixbufLoader *loader;
35 GError *error = NULL((void*)0);
36
37 loader = cdk_pixbuf_loader_new ();
38 path = g_test_get_filename (G_TEST_DIST, "test-images/randomly-modified", filename, NULL((void*)0));
39
40 g_test_message ("reading %s", path);
41 file = g_fopenfopen (path, "rb");
42 g_assert (file != NULL)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_11
= 0; if (file != ((void*)0)) _g_boolean_var_11 = 1; _g_boolean_var_11
; }), 1)) ; else g_assertion_message_expr (((gchar*) 0), "../tests/pixbuf-threads.c"
, 42, ((const char*) (__func__)), "file != NULL"); } while (0
)
;
1
Taking true branch
2
Taking true branch
3
Loop condition is false. Exiting loop
43
44 while (!feof (file))
4
Loop condition is true. Entering loop body
9
Loop condition is true. Entering loop body
45 {
46 nbytes = fread (buffer, 1, sizeof (buffer), file);
5
Assuming this stream operation fails
10
File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior
47 cdk_pixbuf_loader_write (loader, buffer, nbytes, &error);
48 g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "../tests/pixbuf-threads.c"
, 48, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
6
Assuming 'error' is null
7
Taking false branch
8
Loop condition is false. Exiting loop
49 g_thread_yield ();
50 }
51
52 fclose (file);
53
54 cdk_pixbuf_loader_close (loader, &error);
55
56 if (g_error_matches (error, CDK_PIXBUF_ERRORcdk_pixbuf_error_quark (), CDK_PIXBUF_ERROR_UNKNOWN_TYPE))
57 {
58 g_test_message ("Unsupported format");
59 g_clear_error (&error);
60 }
61
62 g_assert_no_error (error)do { if (error) g_assertion_message_error (((gchar*) 0), "../tests/pixbuf-threads.c"
, 62, ((const char*) (__func__)), "error", error, 0, 0); } while
(0)
;
63
64 g_object_unref (loader);
65}
66
67static void
68test_threads (void)
69{
70 GThreadPool *pool;
71 gint iterations;
72 gint i;
73
74 pool = g_thread_pool_new (load_image, NULL((void*)0), 20, FALSE(0), NULL((void*)0));
75
76 if (g_test_thorough ()(!g_test_config_vars->test_quick))
77 iterations = 100;
78 else
79 iterations = 1;
80
81 for (i = 0; i < iterations; i++)
82 {
83 if (format_supported ("jpeg"))
84 g_thread_pool_push (pool, "valid.1.jpeg", NULL((void*)0));
85 if (format_supported ("png"))
86 g_thread_pool_push (pool, "valid.1.png", NULL((void*)0));
87 if (format_supported ("gif"))
88 g_thread_pool_push (pool, "valid.1.gif", NULL((void*)0));
89 if (format_supported ("bmp"))
90 g_thread_pool_push (pool, "valid.1.bmp", NULL((void*)0));
91 if (format_supported ("jpeg"))
92 g_thread_pool_push (pool, "valid.2.jpeg", NULL((void*)0));
93 if (format_supported ("xpm"))
94 g_thread_pool_push (pool, "valid.1.xpm", NULL((void*)0));
95 if (format_supported ("tga"))
96 g_thread_pool_push (pool, "valid.1.tga", NULL((void*)0));
97 if (format_supported ("tiff"))
98 g_thread_pool_push (pool, "valid.1.tiff", NULL((void*)0));
99 }
100
101 g_thread_pool_free (pool, FALSE(0), TRUE(!(0)));
102}
103
104int
105main (int argc, char **argv)
106{
107 g_test_init (&argc, &argv, NULL((void*)0));
108
109 g_test_add_func ("/pixbuf/threads", test_threads);
110
111 return g_test_run ();
112}