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 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> |
21 | #endif /* HAVE_CONFIG_H */ |
22 | |
23 | #ifdef HAVE_STDIO_H |
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 | |
31 | const gchar *plugin_name = "i8k"; |
32 | |
33 | #define I8K_DEVICE_PATH "/proc/i8k" |
34 | #define I8K_DEVICE_FILE "i8k" |
35 | |
36 | enum { |
37 | I8K_DEVICE_FILE_OPEN_ERROR, |
38 | I8K_DEVICE_FILE_READ_ERROR |
39 | }; |
40 | |
41 | static void i8k_plugin_setup_manually(GList **sensors) { |
42 | if (g_file_test(I8K_DEVICE_PATH, G_FILE_TEST_EXISTS)) { |
43 | |
44 | |
45 | sensors_applet_plugin_add_sensor(sensors, |
46 | I8K_DEVICE_PATH, |
47 | "temp1", |
48 | _("CPU"), |
49 | TEMP_SENSOR, |
50 | TRUE, |
51 | CPU_ICON, |
52 | DEFAULT_GRAPH_COLOR); |
53 | |
54 | sensors_applet_plugin_add_sensor(sensors, |
55 | I8K_DEVICE_PATH, |
56 | "fan1", |
57 | _("FAN1"), |
58 | FAN_SENSOR, |
59 | FALSE, |
60 | FAN_ICON, |
61 | DEFAULT_GRAPH_COLOR); |
62 | |
63 | sensors_applet_plugin_add_sensor(sensors, |
64 | I8K_DEVICE_PATH, |
65 | "fan2", |
66 | _("FAN2"), |
67 | FAN_SENSOR, |
68 | FALSE, |
69 | FAN_ICON, |
70 | DEFAULT_GRAPH_COLOR); |
71 | } |
72 | } |
73 | |
74 | |
75 | static GList *i8k_plugin_init(void) { |
76 | GList *sensors = NULL; |
77 | |
78 | i8k_plugin_setup_manually(&sensors); |
79 | |
80 | return sensors; |
81 | } |
82 | |
83 | gdouble i8k_plugin_get_sensor_value(const gchar *path, |
84 | const gchar *id, |
85 | SensorType type, |
86 | GError **error) { |
87 | |
88 | |
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 == (fp = fopen(path, "r"))) { |
| |
95 | g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 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 | |
103 | |
104 | |
105 | while (file_length < 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 this stream operation fails | |
|
| |
| 7 | | File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior |
|
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, 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, 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, I8K_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); |
144 | return -1.0; |
145 | } |
146 | |
147 | return (gdouble)sensor_value; |
148 | |
149 | } |
150 | |
151 | const gchar *sensors_applet_plugin_name(void) |
152 | { |
153 | return plugin_name; |
154 | } |
155 | |
156 | GList *sensors_applet_plugin_init(void) |
157 | { |
158 | return i8k_plugin_init(); |
159 | } |
160 | |
161 | gdouble 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 | } |