Bug Summary

File:plugins/i8k/i8k-plugin.c
Warning:line 106, column 13
Read function called when stream is in EOF state. Function has no effect

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 i8k-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 -fdebug-compilation-dir=/rootdir/plugins/i8k -fcoverage-compilation-dir=/rootdir/plugins/i8k -resource-dir /usr/lib/llvm-19/lib/clang/19 -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/sysprof-6 -I /usr/include/libmount -I /usr/include/blkid -D PIC -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 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -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-02-12-071142-80970-1 -x c i8k-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 "i8k-plugin.h"
30
31const gchar *plugin_name = "i8k";
32
33#define I8K_DEVICE_PATH"/proc/i8k" "/proc/i8k"
34#define I8K_DEVICE_FILE"i8k" "i8k"
35
36enum {
37 I8K_DEVICE_FILE_OPEN_ERROR,
38 I8K_DEVICE_FILE_READ_ERROR
39};
40
41static void i8k_plugin_setup_manually(GList **sensors) {
42 if (g_file_test(I8K_DEVICE_PATH"/proc/i8k", G_FILE_TEST_EXISTS)) {
43 /* with i8k have only 3 fixed sensors, all accessed
44 from the I8K_DEVICE_PATH */
45 sensors_applet_plugin_add_sensor(sensors,
46 I8K_DEVICE_PATH"/proc/i8k",
47 "temp1",
48 _("CPU")gettext ("CPU"),
49 TEMP_SENSOR,
50 TRUE(!(0)),
51 CPU_ICON,
52 DEFAULT_GRAPH_COLOR"#ff0000");
53
54 sensors_applet_plugin_add_sensor(sensors,
55 I8K_DEVICE_PATH"/proc/i8k",
56 "fan1",
57 _("FAN1")gettext ("FAN1"),
58 FAN_SENSOR,
59 FALSE(0),
60 FAN_ICON,
61 DEFAULT_GRAPH_COLOR"#ff0000");
62
63 sensors_applet_plugin_add_sensor(sensors,
64 I8K_DEVICE_PATH"/proc/i8k",
65 "fan2",
66 _("FAN2")gettext ("FAN2"),
67 FAN_SENSOR,
68 FALSE(0),
69 FAN_ICON,
70 DEFAULT_GRAPH_COLOR"#ff0000");
71 }
72}
73
74/* to be called externally to setup for i8k sensors */
75static GList *i8k_plugin_init(void) {
76 GList *sensors = NULL((void*)0);
77
78 i8k_plugin_setup_manually(&sensors);
79
80 return sensors;
81}
82
83gdouble i8k_plugin_get_sensor_value(const gchar *path,
84 const gchar *id,
85 SensorType type,
86 GError **error) {
87
88 /* to open and access the value of each sensor */
89 FILE *fp;
90 gint cpu_temp, fan1_status, fan2_status, fan1_rpm, fan2_rpm;
91 gint sensor_value;
92 gint space_count, file_length;
93
94 if (NULL((void*)0) == (fp = fopen(path, "r"))) {
2
Taking false branch
95 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), I8K_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path);
96 return -1.0;
97 }
98
99 space_count = 0;
100 file_length = 0;
101
102 /* count spaces but stop if have counted 100 characters and
103 still not found a space (to avoid infinite loop if file
104 format error) */
105 while (file_length
2.1
'file_length' is < 100
5.1
'file_length' is < 100
< 100 && space_count < 3) {
3
Loop condition is true. Entering loop body
6
Loop condition is true. Entering loop body
106 if (fgetc(fp) == ' ') {
4
Assuming stream reaches end-of-file here
5
Taking false branch
7
Read function called when stream is in EOF state. Function has no effect
107 space_count++;
108 }
109 file_length++;
110 }
111
112 if (fscanf(fp, "%d %d %d %d %d", &cpu_temp, &fan1_status, &fan2_status, &fan1_rpm, &fan2_rpm) != 5) {
113 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
114 fclose(fp);
115 return -1.0;
116 }
117 fclose(fp);
118
119 switch (type) {
120 case TEMP_SENSOR:
121 sensor_value = cpu_temp;
122 break;
123
124 case FAN_SENSOR:
125 switch (id[3]) {
126 case '1':
127 sensor_value = fan1_rpm;
128 break;
129
130 case '2':
131 sensor_value = fan2_rpm;
132 break;
133
134 default:
135 g_error("Error in i8k sensor get value function code for id %s", id);
136 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
137 return -1.0;
138 }
139 break;
140
141 default:
142 g_error("Unknown sensor type passed as parameter to i8k sensor interface, cannot get value for this sensor");
143 g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR(sensors_applet_plugin_error_quark()), I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path);
144 return -1.0;
145 } // end switch (sensor_type)
146
147 return (gdouble)sensor_value;
148
149}
150
151const gchar *sensors_applet_plugin_name(void)
152{
153 return plugin_name;
154}
155
156GList *sensors_applet_plugin_init(void)
157{
158 return i8k_plugin_init();
159}
160
161gdouble sensors_applet_plugin_get_sensor_value(const gchar *path,
162 const gchar *id,
163 SensorType type,
164 GError **error) {
165
166 return i8k_plugin_get_sensor_value(path, id, type, error);
1
Calling 'i8k_plugin_get_sensor_value'
167}