Bug Summary

File:_build/../testsuite/test-language.c
Warning:line 92, column 15
Access of 'glob' 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-language.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-language.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-language.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) 2013 - 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 CtkSourceLanguageManager *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 **lang_dirs;
44
45 dir = g_build_filename (TOP_SRCDIR"/rootdir", "data", "language-specs", NULL((void*)0));
46
47 fixture->manager = ctk_source_language_manager_get_default ();
48
49 if (g_file_test (dir, G_FILE_TEST_IS_DIR))
50 {
51 lang_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 lang_dirs[0] = dir;
53 lang_dirs[1] = g_test_build_filename (G_TEST_DIST, "language-specs", 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_language_manager_get_search_path (fixture->manager);
63 lang_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 lang_dirs[i] = g_strdup(current[i])g_strdup_inline (current[i]);
67 }
68 lang_dirs[i] = g_test_build_filename (G_TEST_DIST, "language-specs", NULL((void*)0));
69 }
70
71 ctk_source_language_manager_set_search_path (fixture->manager, lang_dirs);
72 g_strfreev (lang_dirs);
73}
74
75static void
76test_fixture_teardown (TestFixture *fixture,
77 gconstpointer data)
78{
79}
80
81static void
82compare_strv_unordered (const gchar **strv,
83 const gchar **expected_strv)
84{
85 if (expected_strv
17.1
'expected_strv' is not equal to NULL
!= NULL((void*)0))
18
Taking true branch
86 {
87 guint i;
88
89 g_assert_cmpuint (g_strv_length ((gchar **) strv), ==,do { guint64 __n1 = (g_strv_length ((gchar **) strv)), __n2 =
(g_strv_length ((gchar **) expected_strv)); if (__n1 == __n2
) ; else g_assertion_message_cmpint ("CtkSourceView", "../testsuite/test-language.c"
, 90, ((const char*) (__func__)), "g_strv_length ((gchar **) strv)"
" " "==" " " "g_strv_length ((gchar **) expected_strv)", __n1
, "==", __n2, 'u'); } while (0)
19
Assuming '__n1' is equal to '__n2'
20
Taking true branch
21
Loop condition is false. Exiting loop
90 g_strv_length ((gchar **) expected_strv))do { guint64 __n1 = (g_strv_length ((gchar **) strv)), __n2 =
(g_strv_length ((gchar **) expected_strv)); if (__n1 == __n2
) ; else g_assertion_message_cmpint ("CtkSourceView", "../testsuite/test-language.c"
, 90, ((const char*) (__func__)), "g_strv_length ((gchar **) strv)"
" " "==" " " "g_strv_length ((gchar **) expected_strv)", __n1
, "==", __n2, 'u'); } while (0)
;
91
92 for (i = 0; expected_strv[i] != NULL((void*)0); i++)
22
Assuming the condition is true
23
Loop condition is true. Entering loop body
28
Assuming the condition is true
29
Loop condition is true. Entering loop body
34
Assuming the condition is true
35
Loop condition is true. Entering loop body
40
Access of 'glob' at index 3, while it holds only 3 'const char *' elements
93 {
94 g_assert_true (g_strv_contains (strv, expected_strv[i]))do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_12
= 0; if (g_strv_contains (strv, expected_strv[i])) _g_boolean_var_12
= 1; _g_boolean_var_12; }), 1)) ; else g_assertion_message (
"CtkSourceView", "../testsuite/test-language.c", 94, ((const char
*) (__func__)), "'" "g_strv_contains (strv, expected_strv[i])"
"' should be TRUE"); } while (0)
;
24
Assuming the condition is true
25
Taking true branch
26
Taking true branch
27
Loop condition is false. Exiting loop
30
Assuming the condition is true
31
Taking true branch
32
Taking true branch
33
Loop condition is false. Exiting loop
36
Assuming the condition is true
37
Taking true branch
38
Taking true branch
39
Loop condition is false. Exiting loop
95 }
96 }
97 else
98 {
99 g_assert_null (strv)do { if (__builtin_expect (__extension__ ({ int _g_boolean_var_13
= 0; if ((strv) == ((void*)0)) _g_boolean_var_13 = 1; _g_boolean_var_13
; }), 1)) ; else g_assertion_message ("CtkSourceView", "../testsuite/test-language.c"
, 99, ((const char*) (__func__)), "'" "strv" "' should be NULL"
); } while (0)
;
100 }
101}
102
103static void
104check_language (CtkSourceLanguage *language,
105 const gchar *id,
106 const gchar *expected_name,
107 const gchar *expected_section,
108 gboolean expected_hidden,
109 const gchar *expected_extra_meta,
110 const gchar **expected_mime,
111 const gchar **expected_glob,
112 const gchar **expected_styles,
113 const gchar *style_id,
114 const gchar *expected_style_name)
115{
116 gchar **mime;
117 gchar **glob;
118 gchar **styles;
119
120 g_assert_cmpstr (ctk_source_language_get_id (language), ==, id)do { const char *__s1 = (ctk_source_language_get_id (language
)), *__s2 = (id); if (g_strcmp0 (__s1, __s2) == 0) ; else g_assertion_message_cmpstr
("CtkSourceView", "../testsuite/test-language.c", 120, ((const
char*) (__func__)), "ctk_source_language_get_id (language)" " "
"==" " " "id", __s1, "==", __s2); } while (0)
;
2
Assuming the condition is true
3
Taking true branch
4
Loop condition is false. Exiting loop
121 g_assert_cmpstr (ctk_source_language_get_name (language), ==, expected_name)do { const char *__s1 = (ctk_source_language_get_name (language
)), *__s2 = (expected_name); if (g_strcmp0 (__s1, __s2) == 0)
; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-language.c"
, 121, ((const char*) (__func__)), "ctk_source_language_get_name (language)"
" " "==" " " "expected_name", __s1, "==", __s2); } while (0)
;
5
Assuming the condition is true
6
Taking true branch
7
Loop condition is false. Exiting loop
122 g_assert_cmpstr (ctk_source_language_get_section (language), ==, expected_section)do { const char *__s1 = (ctk_source_language_get_section (language
)), *__s2 = (expected_section); if (g_strcmp0 (__s1, __s2) ==
0) ; else g_assertion_message_cmpstr ("CtkSourceView", "../testsuite/test-language.c"
, 122, ((const char*) (__func__)), "ctk_source_language_get_section (language)"
" " "==" " " "expected_section", __s1, "==", __s2); } while (
0)
;
8
Assuming the condition is true
9
Taking true branch
10
Loop condition is false. Exiting loop
123 g_assert_cmpint (ctk_source_language_get_hidden (language), ==, expected_hidden)do { gint64 __n1 = (ctk_source_language_get_hidden (language)
), __n2 = (expected_hidden); if (__n1 == __n2) ; else g_assertion_message_cmpint
("CtkSourceView", "../testsuite/test-language.c", 123, ((const
char*) (__func__)), "ctk_source_language_get_hidden (language)"
" " "==" " " "expected_hidden", (guint64)__n1, "==", (guint64
)__n2, 'i'); } while (0)
;
11
Assuming '__n1' is equal to '__n2'
12
Taking true branch
13
Loop condition is false. Exiting loop
124 g_assert_cmpstr (ctk_source_language_get_metadata (language, "extra-meta"), ==, expected_extra_meta)do { const char *__s1 = (ctk_source_language_get_metadata (language
, "extra-meta")), *__s2 = (expected_extra_meta); if (g_strcmp0
(__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView"
, "../testsuite/test-language.c", 124, ((const char*) (__func__
)), "ctk_source_language_get_metadata (language, \"extra-meta\")"
" " "==" " " "expected_extra_meta", __s1, "==", __s2); } while
(0)
;
14
Assuming the condition is true
15
Taking true branch
16
Loop condition is false. Exiting loop
125
126 mime = ctk_source_language_get_mime_types (language);
127 compare_strv_unordered ((const gchar **) mime, expected_mime);
128 g_strfreev (mime);
129
130 glob = ctk_source_language_get_globs (language);
131 compare_strv_unordered ((const gchar **) glob, expected_glob);
17
Calling 'compare_strv_unordered'
132 g_strfreev (glob);
133
134 styles = ctk_source_language_get_style_ids (language);
135 compare_strv_unordered ((const gchar **) styles, expected_styles);
136 g_strfreev (styles);
137
138 if (expected_style_name != NULL((void*)0))
139 {
140 g_assert_cmpstr (ctk_source_language_get_style_name (language, style_id), ==, expected_style_name)do { const char *__s1 = (ctk_source_language_get_style_name (
language, style_id)), *__s2 = (expected_style_name); if (g_strcmp0
(__s1, __s2) == 0) ; else g_assertion_message_cmpstr ("CtkSourceView"
, "../testsuite/test-language.c", 140, ((const char*) (__func__
)), "ctk_source_language_get_style_name (language, style_id)"
" " "==" " " "expected_style_name", __s1, "==", __s2); } while
(0)
;
141 }
142}
143
144static void
145test_language (TestFixture *fixture,
146 gconstpointer data)
147{
148 CtkSourceLanguage *language;
149 const gchar *mime[] = { "text/x-test", "application/x-test", NULL((void*)0)};
150 const gchar *glob[] = { "*.test", "*.tst", NULL((void*)0)};
151 const gchar *styles[] = { "test-full:keyword", "test-full:string", NULL((void*)0)};
152
153 language = ctk_source_language_manager_get_language (fixture->manager, "test-full");
154 check_language (language, "test-full", "Test Full", "Sources", FALSE(0), "extra", mime, glob, styles, "test-full:string", "String");
1
Calling 'check_language'
155
156 language = ctk_source_language_manager_get_language (fixture->manager, "test-empty");
157 check_language (language, "test-empty", "Test Empty", "Others", TRUE(!(0)), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
158}
159
160int
161main (int argc, char** argv)
162{
163 ctk_test_init (&argc, &argv);
164
165 g_test_add ("/Language/language-properties", TestFixture, NULL, test_fixture_setup, test_language, 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 ("/Language/language-properties"
, sizeof (TestFixture), ((void*)0), test_fixture_setup, test_language
, test_fixture_teardown); } while (0)
;
166
167 return g_test_run();
168}