Bug Summary

File:cpufreq/src/cpufreq-monitor-cpuinfo.c
Warning:line 120, column 24
The left operand of '*' is a garbage value

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 cpufreq-monitor-cpuinfo.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/cpufreq/src -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I ../.. -D CPUFREQ_MENU_UI_DIR="/usr/local/share/cafe/ui" -I /usr/include/cafe-panel-4.0/libcafe-panel-applet -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/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -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/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -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/cpufreq/src -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-01-11-191850-85600-1 -x c cpufreq-monitor-cpuinfo.c
1/*
2 * CAFE CPUFreq Applet
3 * Copyright (C) 2004 Carlos Garcia Campos <carlosgc@gnome.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * Authors : Carlos García Campos <carlosgc@gnome.org>
20 */
21
22#ifdef HAVE_CONFIG_H1
23#include <config.h>
24#endif
25
26#include <glib.h>
27#include <glib/gi18n.h>
28
29#include <string.h>
30#include <stdio.h>
31
32#include "cpufreq-monitor-cpuinfo.h"
33#include "cpufreq-utils.h"
34
35static gboolean cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor);
36
37G_DEFINE_TYPE (CPUFreqMonitorCPUInfo, cpufreq_monitor_cpuinfo, CPUFREQ_TYPE_MONITOR)static void cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo
*self); static void cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass
*klass); static GType cpufreq_monitor_cpuinfo_get_type_once (
void); static gpointer cpufreq_monitor_cpuinfo_parent_class =
((void*)0); static gint CPUFreqMonitorCPUInfo_private_offset
; static void cpufreq_monitor_cpuinfo_class_intern_init (gpointer
klass) { cpufreq_monitor_cpuinfo_parent_class = g_type_class_peek_parent
(klass); if (CPUFreqMonitorCPUInfo_private_offset != 0) g_type_class_adjust_private_offset
(klass, &CPUFreqMonitorCPUInfo_private_offset); cpufreq_monitor_cpuinfo_class_init
((CPUFreqMonitorCPUInfoClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer cpufreq_monitor_cpuinfo_get_instance_private
(CPUFreqMonitorCPUInfo *self) { return (((gpointer) ((guint8
*) (self) + (glong) (CPUFreqMonitorCPUInfo_private_offset))))
; } GType cpufreq_monitor_cpuinfo_get_type (void) { static gsize
static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); (void) (0 ? (gpointer) *(
&static_g_define_type_id) : ((void*)0)); (!(__extension__
({ _Static_assert (sizeof *(&static_g_define_type_id) ==
sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter (&static_g_define_type_id
)); }))) { GType g_define_type_id = cpufreq_monitor_cpuinfo_get_type_once
(); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); 0 ?
(void) (*(&static_g_define_type_id) = (g_define_type_id)
) : (void) 0; g_once_init_leave ((&static_g_define_type_id
), (gsize) (g_define_type_id)); })); } return static_g_define_type_id
; } __attribute__ ((__noinline__)) static GType cpufreq_monitor_cpuinfo_get_type_once
(void) { GType g_define_type_id = g_type_register_static_simple
((cpufreq_monitor_get_type ()), g_intern_static_string ("CPUFreqMonitorCPUInfo"
), sizeof (CPUFreqMonitorCPUInfoClass), (GClassInitFunc)(void
(*)(void)) cpufreq_monitor_cpuinfo_class_intern_init, sizeof
(CPUFreqMonitorCPUInfo), (GInstanceInitFunc)(void (*)(void))
cpufreq_monitor_cpuinfo_init, (GTypeFlags) 0); { {{};} } return
g_define_type_id; }
38
39static void
40cpufreq_monitor_cpuinfo_init (CPUFreqMonitorCPUInfo *monitor)
41{
42}
43
44static void
45cpufreq_monitor_cpuinfo_class_init (CPUFreqMonitorCPUInfoClass *klass)
46{
47 CPUFreqMonitorClass *monitor_class = CPUFREQ_MONITOR_CLASS (klass)((((CPUFreqMonitorClass*) (void *) g_type_check_class_cast ((
GTypeClass*) ((klass)), ((cpufreq_monitor_get_type ()))))))
;
48
49 monitor_class->run = cpufreq_monitor_cpuinfo_run;
50}
51
52CPUFreqMonitor *
53cpufreq_monitor_cpuinfo_new (guint cpu)
54{
55 CPUFreqMonitorCPUInfo *monitor;
56
57 monitor = g_object_new (CPUFREQ_TYPE_MONITOR_CPUINFO(cpufreq_monitor_cpuinfo_get_type ()), "cpu", cpu, NULL((void*)0));
58
59 return CPUFREQ_MONITOR (monitor)((((CPUFreqMonitor*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((monitor)), ((cpufreq_monitor_get_type ()))))))
;
60}
61
62static gboolean
63cpufreq_monitor_cpuinfo_run (CPUFreqMonitor *monitor)
64{
65 gchar *file;
66 gchar **lines;
67 gchar *buffer = NULL((void*)0);
68 gchar *p;
69 gint cpu, i;
1
'cpu' declared without an initial value
70 gint cur_freq, max_freq;
71 gchar *governor;
72 GError *error = NULL((void*)0);
73
74 file = g_strdup ("/proc/cpuinfo")g_strdup_inline ("/proc/cpuinfo");
75 if (!cpufreq_file_get_contents (file, &buffer, NULL((void*)0), &error)) {
2
Assuming the condition is false
3
Taking false branch
76 g_warning ("%s", error->message);
77 g_error_free (error);
78
79 g_free (file);
80
81 return FALSE(0);
82 }
83 g_free (file);
84
85 /* TODO: SMP support */
86 lines = g_strsplit (buffer, "\n", -1);
87 for (i = 0; lines[i]; i++) {
4
Loop condition is false. Execution continues on line 116
88 if (g_ascii_strncasecmp ("cpu MHz", lines[i], strlen ("cpu MHz")) == 0) {
89 p = g_strrstr (lines[i], ":");
90
91 if (p == NULL((void*)0)) {
92 g_strfreev (lines);
93 g_free (buffer);
94
95 return FALSE(0);
96 }
97
98 if (strlen (lines[i]) < (size_t)(p - lines[i])) {
99 g_strfreev (lines);
100 g_free (buffer);
101
102 return FALSE(0);
103 }
104
105 if ((sscanf (p + 1, "%d.", &cpu)) != 1) {
106 g_strfreev (lines);
107 g_free (buffer);
108
109 return FALSE(0);
110 }
111
112 break;
113 }
114 }
115
116 g_strfreev (lines);
117 g_free (buffer);
118
119 governor = g_strdup (_("Frequency Scaling Unsupported"))g_strdup_inline (gettext ("Frequency Scaling Unsupported"));
120 cur_freq = cpu * 1000;
5
The left operand of '*' is a garbage value
121 max_freq = cur_freq;
122
123 g_object_set (G_OBJECT (monitor)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((monitor)), (((GType) ((20) << (2))))))))
,
124 "governor", governor,
125 "frequency", cur_freq,
126 "max-frequency", max_freq,
127 NULL((void*)0));
128
129 g_free (governor);
130
131 return TRUE(!(0));
132}
133
134
135
136