Bug Summary

File:plugins/ibm-acpi/ibm-acpi-plugin.c
Warning:line 204, column 5
Undefined or garbage value returned to caller

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 ibm-acpi-plugin.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 -fhalf-no-semantic-interposition -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/plugins/ibm-acpi -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I ../../sensors-applet -D CAFELOCALEDIR="/usr/share/locale/" -D G_LOG_DOMAIN="sensors-applet" -D PIXMAPS_DIR="/usr/share/pixmaps/cafe-sensors-applet/" -D DATADIR="/usr/share" -D LIBDIR="/usr/lib" -D SYSCONFDIR="/usr/etc" -D PREFIX="/usr" -I ../.. -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 -D PIC -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/plugins/ibm-acpi -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-11-203812-82803-1 -x c ibm-acpi-plugin.c
1/*
2 * Copyright (C) 2005-2009 Alex Murray <murray.alex@gmail.com>
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 of the License, or
7 * (at your option) 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 St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifdef HAVE_CONFIG_H1
20#include "config.h"
21#endif /* HAVE_CONFIG_H */
22
23#ifdef HAVE_STDIO_H1
24#include <stdio.h>
25#endif /* HAVE_STDIO_H */
26
27#include <glib.h>
28#include <glib/gi18n.h>
29#include "ibm-acpi-plugin.h"
30
31const gchar *plugin_name = "ibm-acpi";
32
33#define IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal" "/proc/acpi/ibm/thermal"
34#define IBM_ACPI_FAN_FILE"/proc/acpi/ibm/fan" "/proc/acpi/ibm/fan"
35
36/* sensor id's */
37#define CPU"CPU" "CPU"
38#define MPCI"mPCI" "mPCI"
39#define HDD"HDD" "HDD"
40#define GPU"GPU" "GPU"
41#define BAT0"BAT0" "BAT0"
42#define BAT1"BAT1" "BAT1"
43#define FAN"FAN" "FAN"
44
45
46enum {
47 IBM_ACPI_FILE_OPEN_ERROR,
48 IBM_ACPI_FILE_READ_ERROR
49};
50
51
52static void ibm_acpi_plugin_setup_manually(GList **sensors) {
53 gchar *label;
54
55 if (g_file_test(IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal", G_FILE_TEST_EXISTS)) {
56
57 /* with Ibm_Acpi have 8 fixed sensors, all accessed
58 from the IBM_ACPI_TEMPERATURE_FILE */
59 sensors_applet_plugin_add_sensor(sensors,
60 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
61 CPU"CPU",
62 _(CPU)gettext ("CPU"),
63 TEMP_SENSOR,
64 TRUE(!(0)),
65 CPU_ICON,
66 DEFAULT_GRAPH_COLOR"#ff0000");
67
68 sensors_applet_plugin_add_sensor(sensors,
69 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
70 MPCI"mPCI",
71 _("MiniPCI")gettext ("MiniPCI"),
72 TEMP_SENSOR,
73 FALSE(0),
74 GENERIC_ICON,
75 DEFAULT_GRAPH_COLOR"#ff0000");
76
77 sensors_applet_plugin_add_sensor(sensors,
78 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
79 HDD"HDD",
80 _(HDD)gettext ("HDD"),
81 TEMP_SENSOR,
82 FALSE(0),
83 HDD_ICON,
84 DEFAULT_GRAPH_COLOR"#ff0000");
85
86 sensors_applet_plugin_add_sensor(sensors,
87 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
88 GPU"GPU",
89 _(GPU)gettext ("GPU"),
90 TEMP_SENSOR,
91 FALSE(0),
92 GPU_ICON,
93 DEFAULT_GRAPH_COLOR"#ff0000");
94
95 label = g_strdup_printf("%s %d", _("Battery")gettext ("Battery"), 0);
96 sensors_applet_plugin_add_sensor(sensors,
97 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
98 BAT0"BAT0",
99 label,
100 TEMP_SENSOR,
101 FALSE(0),
102 BATTERY_ICON,
103 DEFAULT_GRAPH_COLOR"#ff0000");
104
105 g_free(label);
106
107 label = g_strdup_printf("%s %d", _("Battery")gettext ("Battery"), 0);
108 sensors_applet_plugin_add_sensor(sensors,
109 IBM_ACPI_TEMPERATURE_FILE"/proc/acpi/ibm/thermal",
110 BAT1"BAT1",
111 label,
112 TEMP_SENSOR,
113 FALSE(0),
114 BATTERY_ICON,
115 DEFAULT_GRAPH_COLOR"#ff0000");
116
117 g_free(label);
118 }
119
120 if (g_file_test(IBM_ACPI_FAN_FILE"/proc/acpi/ibm/fan", G_FILE_TEST_EXISTS)) {
121 sensors_applet_plugin_add_sensor(sensors,
122 IBM_ACPI_FAN_FILE"/proc/acpi/ibm/fan",
123 FAN"FAN",
124 _("Fan")gettext ("Fan"),
125 FAN_SENSOR,
126 FALSE(0),
127 FAN_ICON,
128 DEFAULT_GRAPH_COLOR"#ff0000");
129
130 }
131}
132
133/* to be called externally to setup for ibm_acpi sensors */
134GList *ibm_acpi_plugin_init(void) {
135 GList *sensors = NULL((void*)0);
136
137 ibm_acpi_plugin_setup_manually(&sensors);
138
139 return sensors;
140}
141
142gdouble ibm_acpi_plugin_get_sensor_value(const gchar *path,
143 const gchar *id,
144 SensorType type,
145 GError **error) {
146
147 /* to open and access the value of each sensor */
148 FILE *fp;
149 gint sensor_value;
2
'sensor_value' declared without an initial value
150 gint cpu_temp, minipci_temp, hdd_temp, gpu_temp, bat0_temp, bat1_temp, unknown0, unknown1;
151 gint fan_speed;
152
153 if (NULL((void*)0) == (fp = fopen(path, "r"))) {
3
Assuming the condition is false
4
Taking false branch
154 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), IBM_ACPI_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
155 return -1.0;
156 }
157
158 switch (type) {
5
Control jumps to 'case FAN_SENSOR:' at line 181
159 case TEMP_SENSOR:
160 if (fscanf(fp, "temperatures: %d %d %d %d %d %d %d %d", &cpu_temp, &minipci_temp, &hdd_temp, &gpu_temp, &bat0_temp, &unknown0, &bat1_temp, &unknown1) != 8) {
161 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
162 fclose(fp);
163 return -1.0;
164 }
165
166 if (g_ascii_strcasecmp(id, CPU"CPU") == 0) {
167 sensor_value = cpu_temp;
168 } else if (g_ascii_strcasecmp(id, MPCI"mPCI") == 0) {
169 sensor_value = minipci_temp;
170 } else if (g_ascii_strcasecmp(id, HDD"HDD") == 0) {
171 sensor_value = hdd_temp;
172 } else if (g_ascii_strcasecmp(id, GPU"GPU") == 0) {
173 sensor_value = gpu_temp;
174 } else if (g_ascii_strcasecmp(id, BAT0"BAT0") == 0) {
175 sensor_value = bat0_temp;
176 } else if (g_ascii_strcasecmp(id, BAT1"BAT1") == 0) {
177 sensor_value = bat1_temp;
178 }
179 break;
180
181 case FAN_SENSOR:
182 /*fscanf(fp, "%*[^\n]");*/ /* Skip to the End of the Line */
183 /*fscanf(fp, "%*1[\n]");*/ /* Skip One Newline */
184 if (fscanf(fp, "%*[^\n]%*1[\n]speed: %d", &fan_speed) != 1) {
6
Assuming the condition is false
7
Taking false branch
185 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
186 fclose(fp);
187 return -1.0;
188 }
189
190 if (g_ascii_strcasecmp(id, "FAN") == 0) {
8
Assuming the condition is false
9
Taking false branch
191 sensor_value = fan_speed;
192 }
193 break;
10
Execution continues on line 202
194
195 default:
196 g_error("Unknown sensor type passed as parameter to ibm-acpi sensor interface, cannot get value for this sensor");
197 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), IBM_ACPI_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
198 fclose(fp);
199 return -1.0;
200 }
201
202 fclose(fp);
203
204 return (gdouble)sensor_value;
11
Undefined or garbage value returned to caller
205
206}
207
208const gchar *sensors_applet_plugin_name(void)
209{
210 return plugin_name;
211}
212
213GList *sensors_applet_plugin_init(void)
214{
215 return ibm_acpi_plugin_init();
216}
217
218gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
219 const gchar *id,
220 SensorType type,
221 GError **error) {
222
223 return ibm_acpi_plugin_get_sensor_value(path, id, type, error);
1
Calling 'ibm_acpi_plugin_get_sensor_value'
224}