Bug Summary

File:_build/../testsuite/test-stylescheme.c
Warning:line 92, column 4
Access of 'authors' at index 3, while it holds only 3 'const char *' elements

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 test-stylescheme.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 -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-19/lib/clang/19 -I testsuite/test-stylescheme.p -I testsuite -I ../testsuite -I . -I .. -I ctksourceview -I /usr/include/fribidi -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 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -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/libxml2 -D _FILE_OFFSET_BITS=64 -D G_LOG_DOMAIN="CtkSourceView" -D TOP_SRCDIR="/rootdir" -U G_DISABLE_ASSERT -U G_DISABLE_CAST_CHECKS -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-cast-function-type -Wno-missing-field-initializers -Wno-sign-compare -Wno-unused-parameter -std=gnu99 -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -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.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/2025-07-25-105050-13980-1 -x c ../testsuite/test-stylescheme.c
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
2/*
3 * This file is part of CtkSourceView
4 *
5 * Copyright (C) 2015 - Paolo Borelli
6 *
7 * CtkSourceView is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * CtkSourceView is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#include <stdlib.h>
26#include <ctk/ctk.h>
27#include <ctksourceview/ctksource.h>
28
29typedef struct _TestFixture TestFixture;
30
31struct _TestFixture {
32 CtkSourceStyleSchemeManager *manager;
33};
34
35/* If we are running from the source dir (e.g. during make check)
36 * we override the path to read from the data dir
37 */
38static void
39test_fixture_setup (TestFixture *fixture,
40 gconstpointer data)
41{
42 gchar *dir;
43 gchar **style_dirs;
44
45 dir = g_build_filename (TOP_SRCDIR"/rootdir", "data", "styles", NULL((void*)0));
46
47 fixture->manager = ctk_source_style_scheme_manager_get_default ();
48
49 if (g_file_test (dir, G_FILE_TEST_IS_DIR))
50 {
51 style_dirs = g_new0 (gchar *, 3)(gchar * *) (__extension__ ({ gsize __n = (gsize) (3); gsize __s
= sizeof (gchar *); gpointer __p; if (__s == 1) __p = g_malloc0
(__n); else if (__builtin_constant_p (__n) && (__s ==
0 || __n <= (9223372036854775807L *2UL+1UL) / __s)) __p =
g_malloc0 (__n * __s); else __p = g_malloc0_n (__n, __s); __p
; }))
;
52 style_dirs[0] = dir;
53 style_dirs[1] = g_test_build_filename (G_TEST_DIST, "styles", NULL((void*)0));
54 }
55 else
56 {
57 const gchar * const *current;
58 int i;
59
60 g_free (dir);
61
62 current = ctk_source_style_scheme_manager_get_search_path (fixture->manager);
63 style_dirs = g_new0 (gchar *, g_strv_length ((gchar **)current) + 2)(gchar * *) (__extension__ ({ gsize __n = (gsize) (g_strv_length
((gchar **)current) + 2); gsize __s = sizeof (gchar *); gpointer
__p; if (__s == 1) __p = g_malloc0 (__n); else if (__builtin_constant_p
(__n) && (__s == 0 || __n <= (9223372036854775807L
*2UL+1UL) / __s)) __p = g_malloc0 (__n * __s); else __p = g_malloc0_n
(__n, __s); __p; }))
;
64 for (i = 0; current[i] != NULL((void*)0); i++)
65 {
66 style_dirs[i] = g_strdup(current[i])g_strdup_inline (current[i]);
67 }
68 style_dirs[i] = g_test_build_filename (G_TEST_DIST, "styles", NULL((void*)0));
69 }
70
71 ctk_source_style_scheme_manager_set_search_path (fixture->manager, style_dirs);
72 g_strfreev (style_dirs);
73}
74
75static void
76test_fixture_teardown (TestFixture *fixture,
77 gconstpointer data)
78{
79}
80
81static void
82compare_strv (const gchar **strv,
83 const gchar **expected_strv)
84{
85 if (expected_strv
11.1
'expected_strv' is not equal to NULL
!= NULL((void*)0))
12
Taking true branch
86 {
87 guint n, i;
88
89 n = g_strv_length ((gchar **) expected_strv);
90 for (i = 0; i < n; i++)
13
Assuming 'i' is < 'n'
14
Loop condition is true. Entering loop body
18
Assuming 'i' is < 'n'
19
Loop condition is true. Entering loop body
23
Assuming 'i' is < 'n'
24
Loop condition is true. Entering loop body
28
Assuming 'i' is < 'n'
29
Loop condition is true. Entering loop body
91 {
92 g_assert_cmpstr (strv[i], ==, expected_strv[i])do { const char *__s1 = (strv[i]), *__s2 = (expected_strv[i])
; if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr
("CtkSourceView", "../testsuite/test-stylescheme.c", 92, ((const
char*) (__func__)), "strv[i]" " " "==" " " "expected_strv[i]"
, __s1, "==", __s2); } while (0)
;
15
Assuming the condition is true
16
Taking true branch
17
Loop condition is false. Exiting loop
20
Assuming the condition is true
21
Taking true branch
22
Loop condition is false. Exiting loop
25
Assuming the condition is true
26
Taking true branch
27
Loop condition is false. Exiting loop
30
Access of 'authors' at index 3, while it holds only 3 'const char *' elements
93 }
94 }
95 else
96 {
97 g_assert_null (strv)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_15
= 0; if ((strv) == ((void*)0)) _g_boolean_var_15 = 1; _g_boolean_var_15
; }), 1)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c"
, 97, ((const char*) (__func__)), "'" "strv" "' should be NULL"
); } while (0)
;
98 }
99}
100
101static void
102check_scheme (CtkSourceStyleScheme *scheme,
103 const gchar *expected_id,
104 const gchar *expected_name,
105 const gchar *expected_description,
106 const gchar **expected_authors,
107 const gchar *style_id,
108 const gchar *background_rgba)
109{
110 CtkSourceStyle *style;
111
112 g_assert_cmpstr (ctk_source_style_scheme_get_id (scheme), ==, expected_id)do { const char *__s1 = (ctk_source_style_scheme_get_id (scheme
)), *__s2 = (expected_id); if (g_strcmp0 (__s1, __s2) == 0) ;
else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c"
, 112, ((const char*) (__func__)), "ctk_source_style_scheme_get_id (scheme)"
" " "==" " " "expected_id", __s1, "==", __s2); } while (0)
;
2
Assuming the condition is true
3
Taking true branch
4
Loop condition is false. Exiting loop
113 g_assert_cmpstr (ctk_source_style_scheme_get_name (scheme), ==, expected_name)do { const char *__s1 = (ctk_source_style_scheme_get_name (scheme
)), *__s2 = (expected_name); if (g_strcmp0 (__s1, __s2) == 0)
; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-stylescheme.c"
, 113, ((const char*) (__func__)), "ctk_source_style_scheme_get_name (scheme)"
" " "==" " " "expected_name", __s1, "==", __s2); } while (0)
;
5
Assuming the condition is true
6
Taking true branch
7
Loop condition is false. Exiting loop
114 g_assert_cmpstr (ctk_source_style_scheme_get_description (scheme), ==, expected_description)do { const char *__s1 = (ctk_source_style_scheme_get_description
(scheme)), *__s2 = (expected_description); if (g_strcmp0 (__s1
, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView"
, "../testsuite/test-stylescheme.c", 114, ((const char*) (__func__
)), "ctk_source_style_scheme_get_description (scheme)" " " "=="
" " "expected_description", __s1, "==", __s2); } while (0)
;
8
Assuming the condition is true
9
Taking true branch
10
Loop condition is false. Exiting loop
115 compare_strv ((const gchar **)ctk_source_style_scheme_get_authors (scheme), expected_authors);
11
Calling 'compare_strv'
116
117 style = ctk_source_style_scheme_get_style (scheme, style_id);
118 g_assert_true (CTK_SOURCE_IS_STYLE (style))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_16
= 0; if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((style)); GType __t = ((ctk_source_style_get_type ())); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))) _g_boolean_var_16
= 1; _g_boolean_var_16; }), 1)) ; else g_assertion_message (
"CtkSourceView", "../testsuite/test-stylescheme.c", 118, ((const
char*) (__func__)), "'" "CTK_SOURCE_IS_STYLE (style)" "' should be TRUE"
); } while (0)
;
119
120 if (background_rgba != NULL((void*)0))
121 {
122 gchar *background = NULL((void*)0);
123
124 g_object_get (style,
125 "background", &background,
126 NULL((void*)0));
127
128 g_assert_cmpstr (background_rgba, ==, background)do { const char *__s1 = (background_rgba), *__s2 = (background
); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr
("CtkSourceView", "../testsuite/test-stylescheme.c", 128, ((
const char*) (__func__)), "background_rgba" " " "==" " " "background"
, __s1, "==", __s2); } while (0)
;
129 g_free (background);
130 }
131}
132
133static void
134test_scheme_properties (TestFixture *fixture,
135 gconstpointer data)
136{
137 CtkSourceStyleScheme *scheme;
138 const gchar *authors[] = { "Paolo Borelli", "John Doe", NULL((void*)0)};
139
140 scheme = ctk_source_style_scheme_manager_get_scheme (fixture->manager, "test");
141
142 check_scheme (scheme, "test", "Test", "Test color scheme", authors, "def:comment", NULL((void*)0));
1
Calling 'check_scheme'
143
144 /* Check that net-address remapped correctly to "underlined" */
145 check_scheme (scheme, "test", "Test", "Test color scheme", authors, "def:net-address", "#FFFFFF");
146}
147
148static void
149test_named_color_alpha (TestFixture *fixture,
150 gconstpointer data)
151{
152 CtkSourceStyleScheme *scheme;
153 CdkRGBA color1, color2;
154 gboolean res;
155
156 scheme = ctk_source_style_scheme_manager_get_scheme (fixture->manager, "test");
157
158 /* Use these two semi private methods to compare a named color and a normal one */
159 res = _ctk_source_style_scheme_get_current_line_color (scheme, &color1);
160 g_assert_true (res)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_17
= 0; if (res) _g_boolean_var_17 = 1; _g_boolean_var_17; }), 1
)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c"
, 160, ((const char*) (__func__)), "'" "res" "' should be TRUE"
); } while (0)
;
161
162 res = _ctk_source_style_scheme_get_background_pattern_color (scheme, &color2);
163 g_assert_true (res)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_18
= 0; if (res) _g_boolean_var_18 = 1; _g_boolean_var_18; }), 1
)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-stylescheme.c"
, 163, ((const char*) (__func__)), "'" "res" "' should be TRUE"
); } while (0)
;
164
165 g_assert_true (cdk_rgba_equal (&color1, &color2))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_19
= 0; if (cdk_rgba_equal (&color1, &color2)) _g_boolean_var_19
= 1; _g_boolean_var_19; }), 1)) ; else g_assertion_message (
"CtkSourceView", "../testsuite/test-stylescheme.c", 165, ((const
char*) (__func__)), "'" "cdk_rgba_equal (&color1, &color2)"
"' should be TRUE"); } while (0)
;
166}
167
168int
169main (int argc, char** argv)
170{
171 ctk_test_init (&argc, &argv);
172
173 g_test_add ("/StyleScheme/scheme-properties", TestFixture, NULL, test_fixture_setup, test_scheme_properties, test_fixture_teardown)do { void (*add_vtable) (const char*, gsize, gconstpointer, void
(*) (TestFixture*, gconstpointer), void (*) (TestFixture*, gconstpointer
), void (*) (TestFixture*, gconstpointer)) = (void (*) (const
gchar *, gsize, gconstpointer, void (*) (TestFixture*, gconstpointer
), void (*) (TestFixture*, gconstpointer), void (*) (TestFixture
*, gconstpointer))) g_test_add_vtable; add_vtable ("/StyleScheme/scheme-properties"
, sizeof (TestFixture), ((void*)0), test_fixture_setup, test_scheme_properties
, test_fixture_teardown); } while (0)
;
174 g_test_add ("/StyleScheme/named-colors-alpha", TestFixture, NULL, test_fixture_setup, test_named_color_alpha, test_fixture_teardown)do { void (*add_vtable) (const char*, gsize, gconstpointer, void
(*) (TestFixture*, gconstpointer), void (*) (TestFixture*, gconstpointer
), void (*) (TestFixture*, gconstpointer)) = (void (*) (const
gchar *, gsize, gconstpointer, void (*) (TestFixture*, gconstpointer
), void (*) (TestFixture*, gconstpointer), void (*) (TestFixture
*, gconstpointer))) g_test_add_vtable; add_vtable ("/StyleScheme/named-colors-alpha"
, sizeof (TestFixture), ((void*)0), test_fixture_setup, test_named_color_alpha
, test_fixture_teardown); } while (0)
;
175
176 return g_test_run();
177}