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-store=region -analyzer-opt-analyze-nested-blocks -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-14/lib/clang/14.0.6 -D HAVE_CONFIG_H -I . -I ../../sensors-applet -D CAFELOCALEDIR="/usr/local/share/locale/" -D G_LOG_DOMAIN="sensors-applet" -D PIXMAPS_DIR="/usr/local/share/pixmaps/cafe-sensors-applet/" -D DATADIR="/usr/local/share" -D LIBDIR="/usr/local/lib" -D SYSCONFDIR="/usr/local/etc" -D PREFIX="/usr/local" -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-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../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/2023-07-21-115029-79067-1 -x c ibm-acpi-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 "ibm-acpi-plugin.h" |
30 | |
31 | const gchar *plugin_name = "ibm-acpi"; |
32 | |
33 | #define IBM_ACPI_TEMPERATURE_FILE "/proc/acpi/ibm/thermal" |
34 | #define IBM_ACPI_FAN_FILE "/proc/acpi/ibm/fan" |
35 | |
36 | |
37 | #define CPU "CPU" |
38 | #define MPCI "mPCI" |
39 | #define HDD "HDD" |
40 | #define GPU "GPU" |
41 | #define BAT0 "BAT0" |
42 | #define BAT1 "BAT1" |
43 | #define FAN "FAN" |
44 | |
45 | |
46 | enum { |
47 | IBM_ACPI_FILE_OPEN_ERROR, |
48 | IBM_ACPI_FILE_READ_ERROR |
49 | }; |
50 | |
51 | |
52 | static void ibm_acpi_plugin_setup_manually(GList **sensors) { |
53 | gchar *label; |
54 | |
55 | if (g_file_test(IBM_ACPI_TEMPERATURE_FILE, G_FILE_TEST_EXISTS)) { |
56 | |
57 | |
58 | |
59 | sensors_applet_plugin_add_sensor(sensors, |
60 | IBM_ACPI_TEMPERATURE_FILE, |
61 | CPU, |
62 | _(CPU), |
63 | TEMP_SENSOR, |
64 | TRUE, |
65 | CPU_ICON, |
66 | DEFAULT_GRAPH_COLOR); |
67 | |
68 | sensors_applet_plugin_add_sensor(sensors, |
69 | IBM_ACPI_TEMPERATURE_FILE, |
70 | MPCI, |
71 | _("MiniPCI"), |
72 | TEMP_SENSOR, |
73 | FALSE, |
74 | GENERIC_ICON, |
75 | DEFAULT_GRAPH_COLOR); |
76 | |
77 | sensors_applet_plugin_add_sensor(sensors, |
78 | IBM_ACPI_TEMPERATURE_FILE, |
79 | HDD, |
80 | _(HDD), |
81 | TEMP_SENSOR, |
82 | FALSE, |
83 | HDD_ICON, |
84 | DEFAULT_GRAPH_COLOR); |
85 | |
86 | sensors_applet_plugin_add_sensor(sensors, |
87 | IBM_ACPI_TEMPERATURE_FILE, |
88 | GPU, |
89 | _(GPU), |
90 | TEMP_SENSOR, |
91 | FALSE, |
92 | GPU_ICON, |
93 | DEFAULT_GRAPH_COLOR); |
94 | |
95 | label = g_strdup_printf("%s %d", _("Battery"), 0); |
96 | sensors_applet_plugin_add_sensor(sensors, |
97 | IBM_ACPI_TEMPERATURE_FILE, |
98 | BAT0, |
99 | label, |
100 | TEMP_SENSOR, |
101 | FALSE, |
102 | BATTERY_ICON, |
103 | DEFAULT_GRAPH_COLOR); |
104 | |
105 | g_free(label); |
106 | |
107 | label = g_strdup_printf("%s %d", _("Battery"), 0); |
108 | sensors_applet_plugin_add_sensor(sensors, |
109 | IBM_ACPI_TEMPERATURE_FILE, |
110 | BAT1, |
111 | label, |
112 | TEMP_SENSOR, |
113 | FALSE, |
114 | BATTERY_ICON, |
115 | DEFAULT_GRAPH_COLOR); |
116 | |
117 | g_free(label); |
118 | } |
119 | |
120 | if (g_file_test(IBM_ACPI_FAN_FILE, G_FILE_TEST_EXISTS)) { |
121 | sensors_applet_plugin_add_sensor(sensors, |
122 | IBM_ACPI_FAN_FILE, |
123 | FAN, |
124 | _("Fan"), |
125 | FAN_SENSOR, |
126 | FALSE, |
127 | FAN_ICON, |
128 | DEFAULT_GRAPH_COLOR); |
129 | |
130 | } |
131 | } |
132 | |
133 | |
134 | GList *ibm_acpi_plugin_init(void) { |
135 | GList *sensors = NULL; |
136 | |
137 | ibm_acpi_plugin_setup_manually(&sensors); |
138 | |
139 | return sensors; |
140 | } |
141 | |
142 | gdouble ibm_acpi_plugin_get_sensor_value(const gchar *path, |
143 | const gchar *id, |
144 | SensorType type, |
145 | GError **error) { |
146 | |
147 | |
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 == (fp = fopen(path, "r"))) { |
| 3 | | Assuming the condition is false | |
|
| |
154 | g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 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, 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) == 0) { |
167 | sensor_value = cpu_temp; |
168 | } else if (g_ascii_strcasecmp(id, MPCI) == 0) { |
169 | sensor_value = minipci_temp; |
170 | } else if (g_ascii_strcasecmp(id, HDD) == 0) { |
171 | sensor_value = hdd_temp; |
172 | } else if (g_ascii_strcasecmp(id, GPU) == 0) { |
173 | sensor_value = gpu_temp; |
174 | } else if (g_ascii_strcasecmp(id, BAT0) == 0) { |
175 | sensor_value = bat0_temp; |
176 | } else if (g_ascii_strcasecmp(id, BAT1) == 0) { |
177 | sensor_value = bat1_temp; |
178 | } |
179 | break; |
180 | |
181 | case FAN_SENSOR: |
182 | |
183 | |
184 | if (fscanf(fp, "%*[^\n]%*1[\n]speed: %d", &fan_speed) != 1) { |
| 6 | | Assuming the condition is false | |
|
| |
185 | g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, 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 | |
|
| |
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, 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 | |
208 | const gchar *sensors_applet_plugin_name(void) |
209 | { |
210 | return plugin_name; |
211 | } |
212 | |
213 | GList *sensors_applet_plugin_init(void) |
214 | { |
215 | return ibm_acpi_plugin_init(); |
216 | } |
217 | |
218 | gdouble 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 | } |